np.where()

a=np.arange(20).reshape(4,5)
a
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19]])

np.where(a>10)
(array([2, 2, 2, 2, 3, 3, 3, 3, 3], dtype=int64),
array([1, 2, 3, 4, 0, 1, 2, 3, 4], dtype=int64))

表示满足条件的值的坐标为(2,1),(2,2),(2,3),(2,4),(3,0),(3,1),(3,2),(3,3),(3,4),也就是11,12,,19所在的坐标,其将横坐标和纵坐标存入不是的array中。

猜你喜欢

转载自blog.csdn.net/weixin_43055882/article/details/86530678
今日推荐