本文主要介绍了np.where()[0] 和 np.where()[1]的具体使用,以及np.where()的具体用法,废话不多说,具体如下:
import numpy as np
a = np.arange(12).reshape(3,4)
print("a:", a)
print("np.where(a > 5):", np.where(a > 5))
print("a[np.where(a > 5)]:", a[np.where(a > 5)])
print("np.where(a > 5)[0]:", np.where(a > 5)[0])
print("np.where(a > 5)[1]:", np.where(a > 5)[1])
print(a[np.where(a > 5)[0], np.where(a > 5)[1]])
a: [[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
np.where(a > 5): (array([1, 1, 2, 2, 2, 2]), array([2, 3, 0, 1, 2, 3]))
a[np.where(a > 5)]: [ 6 7 8 9 10 11]
np.where(a > 5)[0]: [1 1 2 2 2 2]
np.where(a > 5)[1]: [2 3 0 1 2 3]
[ 6 7 8 9 10 11]
np.where()[0] 表示行索引,np.where()[1]表示列索引