PyWavelets
PyWavelets is a free, open-source Python library for wavelet transforms. It provides 1D, 2D, and nD forward and inverse Discrete Wavelet Transforms (DWT and IDWT), Stationary Wavelet Transforms (SWT), Wavelet Packet decomposition, and Continuous Wavelet Transforms (CWT). It combines a simple high-level interface with low-level C and Cython performance and is widely used in signal processing, image compression, and noise removal. The current version is 1.9.0 and it has an active release cadence, with minor updates and new features being released regularly.
Warnings
- breaking PyWavelets 1.9.0 dropped support for Python 3.10 and added support for Python 3.14. Ensure your Python environment meets the minimum requirement of Python >=3.11.
- breaking The minimum supported NumPy version has been updated. PyWavelets 1.9.0 explicitly requires NumPy >= 1.25.0. Using an older NumPy version will likely lead to installation or runtime errors.
- breaking The optional dependency on SciPy for FFT operations was removed in PyWavelets 1.9.0. If your application implicitly relied on SciPy being available due to PyWavelets, it might now be missing.
- gotcha The image returned by `pywt.data.camera` was replaced in version 1.2.0 with a new CC0-licensed image due to licensing restrictions on the original 'cameraman' image. If your application relies on the exact pixel data of the original image, it will be different in newer versions.
- gotcha The length of coefficient arrays returned by `pywt.dwt` depends on the chosen signal extension `mode`. For all modes except 'periodization' ('per'), `len(cA) == len(cD) == floor((len(data) + wavelet.dec_len - 1) / 2)`. For 'periodization' mode, `len(cA) == len(cD) == ceil(len(data) / 2)`. This can lead to unexpected output sizes.
Install
-
pip install PyWavelets
Imports
- pywt
import pywt
Quickstart
import pywt
import numpy as np
data = np.array([1, 2, 3, 4, 5, 6])
wavelet = 'db1'
# Perform a single-level Discrete Wavelet Transform (DWT)
cA, cD = pywt.dwt(data, wavelet)
print(f"Original data: {data}")
print(f"Approximation coefficients (cA): {cA}")
print(f"Detail coefficients (cD): {cD}")
# Perform inverse DWT to reconstruct the signal
reconstructed_data = pywt.idwt(cA, cD, wavelet)
print(f"Reconstructed data: {reconstructed_data}")