Only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or logical arrays are valid indices

I do fft as part of my homework. My problem is implementing shuffling data elements using bit reversal. I get the following warning:

DeprecationWarning: Using a non-integer instead of an integer will result in an error in the future.

data [x], data [y] = data [y], data [x]

And the automatic sorting system (provided by the university) returns the following:

error: only integers, slices ( : , ellipsis ( ... ), numpy.newaxis ( None ), and integer or logical arrays are valid indexes.

My code is:

 def shuffle_bit_reversed_order(data: np.ndarray) -> np.ndarray: """ Shuffle elements of data using bit reversal of list index. Arguments: data: data to be transformed (shape=(n,), dtype='float64') Return: data: shuffled data array """ # implement shuffling by reversing index bits size = data.size half = size/2; for x in range(size): xx = np.int(x) n = np.int(half) y = 0 while n > 0: y += n * np.mod(xx,2) n /= 2 xx = np.int(xx /2) if (y > x): data[x], data[y] = data[y], data[x] return data 

I already implemented a function for fft, but that won't work until I get this shuffle function working. I think the problem is that my data is of type β€œfloat64” and I may have used it as an integer, but I don’t know how I can solve it.

+8
python numpy fft dft
source share
2 answers

I believe your problem is this: in your loop, while n is divisible by 2, but never added as an integer again, so at some point it becomes floating. Then it is added to y, which is also a float, and this gives you a warning.

+14
source share

You can use // instead of single /. This is directly converted to int .

+4
source share

All Articles