本文介绍了只有整数,切片(`:`),省略号(`...`),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:

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

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

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

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

我的代码是:

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`)和整数或布尔数组才是有效索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 04:28