1.numpy.nonzero (condition), returns the Ndarray array formed by the index of the non-0 element of the parameter condition (array or matrix), and can also return a value index with a Boolean value of true in condition, where The value 0 is false and the rest is true.
1>>>b=np.mat (Np.arange (10)). T2>>>b3 Matrix ([[0],4[1],5[2],6[3],7[4],8[5],9[6],Ten[7], One[8], A[9]]) ->>>np.nonzero (b>2) -(Array ([3, 4, 5, 6, 7, 8, 9], dtype=Int64), theArray ([0, 0, 0, 0, 0, 0, 0], dtype=Int64)) ->>>np.nonzero ((b.a>2) * (b.a<8)) -(Array ([3, 4, 5, 6, 7], Dtype=int64), array ([0, 0, 0, 0, 0], Dtype=int64))
1>>> x = Np.eye (3)2>>>x3Array ([[1., 0., 0.],4[0., 1., 0.],5[0., 0., 1.]])6>>>Np.nonzero (x)7(Array ([0, 1, 2]), array ([0, 1, 2]))8>>>9>>>X[np.nonzero (x)]TenArray ([1., 1., 1.]) One>>>Np.transpose (Np.nonzero (x)) A array ([[0, 0], -[1, 1], -[2, 2]]
where Np.nonzero ((b.a>2) * (b.a<8)) is the index that returns the value of array B in the range 2<b<8. and the parameter must be required when the array, if the matrix will error.
A common use for nonzero are to find the indices of an array, where a condition is True. Given an array a, the condition a > 3 are a Boolean array and since False is interpreted as 0, Np.nonz Ero (A > 3) yields the indices of the a where the condition is true. This function is the same as the use of Numpy.where ().
>>> a = Np.array ([[1,2,3],[4,5,6],[7,8,9]]) >>> a > 3array ([False, False, false], [True, True, true], [True, True, true]], Dtype=bool) >>> Np.nonzero (A > 3) (Array ([1, 1, 1, 2, 2, 2 ]), array ([0, 1, 2, 0, 1, 2])
2numpy.multiply ()
Python about array Matrix transform function Numpy.nonzero (), numpy.multiply () usage