只有整数,切片(`:`),省略号(`...`),numpy.newaxis(`None`)和整数或布尔数组才是有效索引 [英] only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

查看:3413
本文介绍了只有整数,切片(`:`),省略号(`...`),numpy.newaxis(`None`)和整数或布尔数组才是有效索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将fft作为作业的一部分.我的问题在于使用位反转实现混排数据元素.我收到以下警告:

I am implementing fft as part of my homework. My problem lies in the implemention of shuffling data elements using bit reversal. I get the following warning:

DeprecationWarning:使用非整数而不是整数会在将来导致错误.

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

数据[x],数据[y] =数据[y],数据[x]

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

自动分级系统(由大学提供)返回以下内容:

And the auto grading system (provided by university) returns the following:

错误:只有整数,切片(:),省略号(...),numpy.newaxis(None)和整数或布尔数组是有效索引.

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

我的代码是:

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

我已经为fft实现了该功能,但是直到我获得了改组功能,该功能才起作用.我认为问题在于我的数据类型为"float64",我可能已将其用作整数,但是我不知道该如何解决.

I have already implemented the function for fft but it won't work until I get this shuffling function working. I think the problem is 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.

推荐答案

我相信您的问题是这样的:在您的while循环中,n被2除,但再也没有将其转换为整数,因此它在某些情况下变成了浮点数.观点.然后将其添加到y上,后者也是一个浮点数,并且会向您发出警告.

I believe your problem is this: in your while loop, n is divided by 2, but never cast as an integer again, so it becomes a float at some point. It is then added onto y, which is then a float too, and that gives you the warning.

这篇关于只有整数,切片(`:`),省略号(`...`),numpy.newaxis(`None`)和整数或布尔数组才是有效索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆