Skip to content

A program error that can cause "IndexError: only integers, ...... are valid indices" #26

@ZhaoKe1024

Description

@ZhaoKe1024

my program is as follows:

    x, _ = librosa.core.load(dataset_path + "test.wav", sr=16000, mono=True)
    x = x[26000:40000]
    wa = WaveletAnalysis(sig, dt=0.1)
    print(wa.reconstruction().shape)

An error occurred during runtime:

  File "\wavelets\transform.py", line 85, in cwt
    return cwt_time(data, wavelet, widths, dt, axis)
  File "\wavelets\transform.py", line 105, in cwt_time
    wavelet_data[slices],
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

Because there is an error in your source code, as shown below,

def cwt_time(data, wavelet, widths, dt, axis):
    # wavelets can be complex so output is complex
    ......
        wavelet_data = norm * wavelet(t, width)
        output[ind, :] = scipy.signal.fftconvolve(data,
                                                  wavelet_data[slices],
                                                  mode='same')
    return output

it should be corrected in this way. Obviously, the sequence value operation is missing:

def cwt_time(data, wavelet, widths, dt, axis):
    # wavelets can be complex so output is complex
    ......
        wavelet_data = norm * wavelet(t, width)
        output[ind, :] = scipy.signal.fftconvolve(data,
                                                  wavelet_data[slices[axis]],
                                                  mode='same')
    return output

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions