我有以下方法:
def unify_np_array(A):
'''Set every nonzero element in a numpy array to 1'''
nonzero = A > 0
A[nonzero] /= A[nonzero]
return A
我使用以下测试代码调用它:
def test_small_np(self):
r = np.array([[3, 0], [0, 2]])
DataConverter.unify_np_array(r)
e = np.array([[1, 0], [0, 1]])
np.testing.assert_array_equal(r, e)
单元测试成功,但我收到以下警告:
DeprecationWarning: Implicitly casting between incompatible kinds.
In a future numpy release, this will raise an error.
Use casting="unsafe" if this is intentional.
A[nonzero] /= A[nonzero]
但是,我没有看到我正在投射哪种不兼容的类型。我将一个numpy数组的子部分与它自己分开。谁能指出我隐含的演员?