Closed RoMa03 closed 3 years ago
The threshold functions do operate on arrays in any number of dimensions. There error in your case is because you were passing in a list of arrays as returned by wavedec
instead of a single array. You would need to call threshold on each individual array. Assuming you intended to apply this same hard threshold to all levels of coefficients, you would need to replace your commented line with:
wav = [pywt.threshold(arr, 3, 'hard') for arr in wav]
A more detailed example with automatic determination of threshold levels and potentially variable thresholds across coefficients can be seen in the _wavelet_threshold method used for denoising in scikit-image.
Thank you for your clear explanation and suggestions.
I do want to apply a fixed threshold to a large set of equal-length vectors. It seems a little counter-intuitive to have to loop through each vector, but perhaps my application is unusual.
I suspect your application is not uncommon.
In principle, the thresholding functions could accept lists of coefficients, however each of the different transforms (wavedecn
, swtn
, fswavedecn
, etc) have a different coefficient format. Handling all of these within the thresholding functions would add quite a bit of complexity.
The question is answered, so I'll close this issue.
The above code runs as I expect, constructing a 1-D wavelet decomposition for each of 2 series and then reconstructing the original series from them. However if the '#' is removed, the result is "ValueError: could not broadcast input array from shape (2,1) into shape (2)". I am not very familiar with the package but this seems strange?