首先看help
upcoef(part, coeffs, wavelet, level=1, take=0)
Direct reconstruction from coefficients.
Parameters
----------
part : str
Coefficients type:
* 'a' - approximations reconstruction is performed
* 'd' - details reconstruction is performed
coeffs : array_like
Coefficients array to recontruct
wavelet : Wavelet object or name
Wavelet to use
level : int, optional
Multilevel reconstruction level. Default is 1.
take : int, optional
Take central part of length equal to 'take' from the result.
Default is 0.
Returns
-------
rec : ndarray
1-D array with reconstructed data from coefficients
#central part怎么理解呢:看如下代码:
data = np.array([8,9,10,11,1,2,3,4,5,6,7]).reshape(-1,)
print('origin data:',data)
(cA, cD) = pywt.dwt(data, 'haar')
print('cA para:',cA)
print('cD para:',cD)
print('take length:len(cA)',len(cA))
print(pywt.upcoef('a', cA, 'haar',take=len(cA)) + pywt.upcoef('d', cD, 'haar',take=len(cD)))
print('take length:len(data)',len(data))
print(pywt.upcoef('a', cA, 'haar',take=len(data)) + pywt.upcoef('d', cD, 'haar',take=len(data)))
print(pywt.upcoef('a', cA, 'haar',take=1) + pywt.upcoef('d', cD, 'haar',take=1))
print(pywt.upcoef('a', cA, 'haar',take=2) + pywt.upcoef('d', cD, 'haar',take=2))
print(pywt.upcoef('a', cA, 'haar',take=3) + pywt.upcoef('d', cD, 'haar',take=3))
print(pywt.upcoef('a', cA, 'haar',take=4) + pywt.upcoef('d', cD, 'haar',take=4))
print(pywt.upcoef('a', cA, 'haar',take=5) + pywt.upcoef('d', cD, 'haar',take=5))
print(pywt.upcoef('a', cA, 'haar',take=6) + pywt.upcoef('d', cD, 'haar',take=6))
print(pywt.upcoef('a', cA, 'haar',take=7) + pywt.upcoef('d', cD, 'haar',take=7))
输出结果:只复制后面take取值1到7的几行
#原始数据:[ 8. 9. 10. 11. 1. 2. 3. 4. 5. 6. 7.]
[2.]
[2. 3.]
[1. 2. 3.]
[1. 2. 3. 4.]
[11. 1. 2. 3. 4.]
[11. 1. 2. 3. 4. 5.]
[10. 11. 1. 2. 3. 4. 5.]
从最中间的位置截取指定长度的数据;如果为1,就是最中间的2;如果为2,就是最中间的两个数,就是2与3;以此类推;
个人理解:这里take原以为可以起到降维作用;事实是不可以的,只是从结果中进行截断;比如说收盘价序列有100个数,take截断后,比如10,那么结果就只有10个数,并不是降维;