Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ZhaoKe1024 opened this issue Dec 28, 2023 · 2 comments

Comments

@ZhaoKe1024
Copy link

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
@ZhaoKe1024 ZhaoKe1024 changed the title A program error that can cause running bugs A program error that can cause "IndexError: only integers, ...... are valid indices" Dec 28, 2023
@endolith
Copy link
Contributor

This repo is abandoned, see my fork and let me know if it has the same problem

@ZhaoKe1024
Copy link
Author

This repo is abandoned, see my fork and let me know if it has the same problem

I just took a look, your program in new repo is correct which added an extra line "slices = tuple(slices)" than the original program, so corrected the error, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants