1

我有以下方法:

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 数组的一个小节与其自身分开。谁能指出我隐含的演员阵容?

4

0 回答 0