Numpy FutureWarning:不推荐使用非元组序列进行多维索引;使用'arr[tuple(seq)]`代替'arr[seq]`

Numpy FutureWarning:不推荐使用非元组序列进行多维索引;使用'arr[tuple(seq)]`代替'arr[seq]`,numpy,future-warning,Numpy,Future Warning,我试图用numpy创建一个混乱矩阵,但我得到了前面的错误。如何修复此问题?如果我们提供的是数组而不是列表,则不会收到未来的警告: In [57]: dW = np.zeros((2,2), int) In [58]: x = [[0,1,1,0,1, 0], [1, 1, 1, 1, 0, 0]] In [59]: np.add.at(dW

我试图用numpy创建一个混乱矩阵,但我得到了前面的错误。如何修复此问题?

如果我们提供的是数组而不是列表,则不会收到未来的警告:

In [57]: dW = np.zeros((2,2), int)                                              

In [58]: x = [[0,1,1,0,1, 0], [1, 1, 1, 1, 0, 0]]                               

In [59]: np.add.at(dW,x,1)                                                      
/home/infinity/anaconda3/bin/ipython:1: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
根据文件,

索引:类数组或元组 类似数组的索引对象或切片对象,用于索引到第一个 操作数。如果第一个操作数有多个维度,则索引可以是 类似数组的索引对象或切片对象的元组

最近的
numpy
版本已经收紧了索引规则。在过去,在真正需要元组或数组的上下文中,有时允许使用列表。这一未来警告是紧缩政策的一部分

===

如评论所述:

In [17]: np.add.at(dW,tuple(x),1)
In [18]: dW
Out[18]: 
array([[6, 7],
       [8, 9]])
In [19]: tuple(x)
Out[19]: ([0, 1, 1, 0, 1, 0], [1, 1, 1, 1, 0, 0])

只是说:如果您使用
tuple()
numpy.array()
,那么
dW
将有所不同。
In [17]: np.add.at(dW,tuple(x),1)
In [18]: dW
Out[18]: 
array([[6, 7],
       [8, 9]])
In [19]: tuple(x)
Out[19]: ([0, 1, 1, 0, 1, 0], [1, 1, 1, 1, 0, 0])
In [22]: In [57]: dW = np.zeros((2,2), int)
    ...: 
In [23]: np.add.at(dW,tuple(x),1)
In [24]: dW
Out[24]: 
array([[1, 2],
       [1, 2]])