FutureWarning:不推荐使用非元组序列进行多维索引;使用 arr[tuple(seq)] 而不是 arr[seq]
FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`
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 [11]: In [57]: dW = np.zeros((2,2), int)
...:
...: In [58]: x = [[0,1,1,0,1, 0], [1, 1, 1, 1, 0, 0]]
In [12]: dW
Out[12]:
array([[0, 0],
[0, 0]])
In [13]: x
Out[13]: [[0, 1, 1, 0, 1, 0], [1, 1, 1, 1, 0, 0]]
In [14]: np.add.at(dW,np.array(x),1)
In [15]: dW
Out[15]:
array([[5, 5],
[7, 7]])
根据文档,
indices : array_like or tuple
Array like index object or slice object for indexing into first
operand. If first operand has multiple dimensions, indices can be a
tuple of array like index objects or slice objects.
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])
最近的 numpy
版本收紧了索引规则。在过去,有时在真正需要元组或数组的上下文中允许使用列表。这个未来警告是紧缩政策的一部分。
===
如评论:
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]])
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 [11]: In [57]: dW = np.zeros((2,2), int)
...:
...: In [58]: x = [[0,1,1,0,1, 0], [1, 1, 1, 1, 0, 0]]
In [12]: dW
Out[12]:
array([[0, 0],
[0, 0]])
In [13]: x
Out[13]: [[0, 1, 1, 0, 1, 0], [1, 1, 1, 1, 0, 0]]
In [14]: np.add.at(dW,np.array(x),1)
In [15]: dW
Out[15]:
array([[5, 5],
[7, 7]])
根据文档,
indices : array_like or tuple Array like index object or slice object for indexing into first operand. If first operand has multiple dimensions, indices can be a tuple of array like index objects or slice objects.
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])
最近的 numpy
版本收紧了索引规则。在过去,有时在真正需要元组或数组的上下文中允许使用列表。这个未来警告是紧缩政策的一部分。
===
如评论:
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]])