1、nonzero
For one-dimensional data, the eligible subscript will be returned
>>> b1 = np.array([True, False, True, False]) >>> np.nonzero(b1) (array([0, 2]),)
For two-dimensional data, a two-dimensional tuple is returned, the first dimension is the index of the eligible x, and the second dimension is the index of the eligible y
>>> b2 = np.array([[True, False, True], [True, False, False]]) >>> np.nonzero(b2) (array([0, 0, 1]), array([0, 2, 0]))
2 、 var, std, cov
var is the variance, std is the standard deviation, cov is the covariance, and the denominator is n-1
import numpy as np # Build the test data with a mean of 10 sc = [9.7, 10, 10.3, 9.7, 10, 10.3, 9.7, 10, 10.3] # output mean 10.0 print(np.mean(sc)) # output var, that is (0.09 + 0 + 0.09 + 0.09 + 0 + 0.09 + 0.09 + 0 + 0.09) = 0.54, then 0.54 / 9=0.06, output 0.06 print (np.var (sc)) # Equivalent to 0.06 root print(np.std(sc)) # 0.54 / 8 = 0.0675 print (np.cov (sc))