2017-05-14 2 views
0

Ich habe ein einfaches Programm, das ich unten eingefügt habe. Ich habe ein Problem, weil, wenn ich das Programm ausführen, bekomme ich einen Fehler. Hier sind meine Fehler:"Axis größer als Daten Dimensionen" - 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 

Und dies ist mein Code:

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]) 

Was, Ihrer Meinung nach, könnte in dem Code ändern, um die Programmarbeit zu machen?

+0

Der Fehler ist in der pywt Modul zur Linie, Linie 90, so sollten Sie uns diesen Code zeigen. –

+0

Außerdem rufen Sie mit dem Aufruf von numpy.darray.shape das 'axis' Element von' shape' ab, und der Fehler besagt, dass größer als die Dimensionen von 'dat.shape' ist –

Antwort

0

Dies ist dieser Code 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 
Verwandte Themen