>>> a = np.random.random((3,4)) >>> a array([[0.890582 , 0.43671675, 0.19531267, 0.13555252], [0.17254557, 0.3088476 , 0.36916878, 0.81551741], [0.31869139, 0.16168486, 0.58004271, 0.4279148 ]]) >>> a.nonzero() (array([0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2]), array([0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3])) >>> a[a.nonzero()] ##方法一,使用矩阵去选择 array([0.890582 , 0.43671675, 0.19531267, 0.13555252, 0.17254557, 0.3088476 , 0.36916878, 0.81551741, 0.31869139, 0.16168486, 0.58004271, 0.4279148 ]) >>> a array([[0.890582 , 0.43671675, 0.19531267, 0.13555252], [0.17254557, 0.3088476 , 0.36916878, 0.81551741], [0.31869139, 0.16168486, 0.58004271, 0.4279148 ]]) >>> a[1,1] ##方法二 0.3088475978138986 >>> a[1][1] ##方法三 0.3088475978138986 >>> a[np.array([[False,False,False,False],[True,True,True,True,], [False,False,False,False]])] array([0.72159605, 0.90488492, 0.60745105, 0.20538722]) ##方法四