2017-05-14 28 views
0

私はプログラムを実行するとエラーが発生するので、私は問題があります。ここに私のエラーです:"Axis from data dimensions" - Python

Traceback (most recent call last): 
    File "C:\Users\Anaconda3\lib\site-packages\pywt\_multilevel.py", line 90, in wavedec 
    axes_shape = data.shape[axis] 
IndexError: tuple index out of range 

During handling of the above exception, another exception occurred: 

python 
Traceback (most recent call last): 
    File "C:/Users/Main.py", line 10, in <module> 
    tree = pywt.wavedec(data=record, wavelet='db2', level=5, mode='symmetric') 
    File "C:\Users\Anaconda3\lib\site-packages\pywt\_multilevel.py", line 92, in wavedec 
    raise ValueError("Axis greater than data dimensions") 
ValueError: Axis greater than data dimensions 

そして、これは私のコードです:

import wfdb 
import pywt 
import matplotlib.pyplot as plt 

record = wfdb.rdsamp('230', sampto = 2000) 
annotation = wfdb.rdann('230', 'atr', sampto = 2000) 

wfdb.plotrec(record, annotation = annotation, title='Output record', timeunits = 'seconds') 

tree = pywt.wavedec(data=record, wavelet='db2', level=5, mode='symmetric') 
newTree = [tree[0], tree[1], tree[2], tree[3]*0, tree[4]*0, tree[5]*0] 
recSignal = pywt.waverec(newTree, 'db2') 

plt.plot(recSignal[:2000]) 

あなたの意見では、プログラムを動作させるために、コードに変更される可能性は何、?

+0

エラー行目には、このコードでは、pywtモジュールにライン90であるので、あなたは私たちにそのコードを表示する必要があります。 –

+0

さらに、numpy.ndarray.shapeを呼び出すと、 'shape'の' axis'要素を取得しています。エラーは 'data.shape'の次元よりも大きいと言います –

答えて

0

これは90

def wavedec(data, wavelet, mode='symmetric', level=None, axis=-1): 
    """ 
    Multilevel 1D Discrete Wavelet Transform of data. 

    Parameters 
    ---------- 
    data: array_like 
     Input data 
    wavelet : Wavelet object or name string 
     Wavelet to use 
    mode : str, optional 
     Signal extension mode, see Modes (default: 'symmetric') 
    level : int, optional 
     Decomposition level (must be >= 0). If level is None (default) then it 
     will be calculated using the ``dwt_max_level`` function. 
    axis: int, optional 
     Axis over which to compute the DWT. If not given, the 
     last axis is used. 

    Returns 
    ------- 
    [cA_n, cD_n, cD_n-1, ..., cD2, cD1] : list 
     Ordered list of coefficients arrays 
     where `n` denotes the level of decomposition. The first element 
     (`cA_n`) of the result is approximation coefficients array and the 
     following elements (`cD_n` - `cD_1`) are details coefficients arrays. 

    Examples 
    -------- 
    >>> from pywt import wavedec 
    >>> coeffs = wavedec([1,2,3,4,5,6,7,8], 'db1', level=2) 
    >>> cA2, cD2, cD1 = coeffs 
    >>> cD1 
    array([-0.70710678, -0.70710678, -0.70710678, -0.70710678]) 
    >>> cD2 
    array([-2., -2.]) 
    >>> cA2 
    array([ 5., 13.]) 

    """ 
    data = np.asarray(data) 

    if not isinstance(wavelet, Wavelet): 
     wavelet = Wavelet(wavelet) 

    try: 
     axes_shape = data.shape[axis] 
    except IndexError: 
     raise ValueError("Axis greater than data dimensions") 
    level = _check_level(axes_shape, wavelet.dec_len, level) 

    coeffs_list = [] 

    a = data 
    for i in range(level): 
     a, d = dwt(a, wavelet, mode, axis) 
     coeffs_list.append(d) 

    coeffs_list.append(a) 
    coeffs_list.reverse() 

    return coeffs_list