np.argwhere()的使用
这是NumPy中用于返回数组中满足条件的元素索引函数
数组可以是多维的吧
参数填写: 数组以及其筛选条件
如
import numpy as np
# 创建一个随机的二维数组
arr = np.random.randint(0, 10, size=(4, 4))
print("Array:\n", arr)
# 返回大于 5 的元素索引
indices = np.argwhere(arr > 5)
print("Indices of elements greater than 5:\n", indices)
输出为:
Array:
[[4 6 7 0]
[9 7 6 3]
[3 3 3 8]
[6 3 1 3]]
Indices of elements greater than 5:
[[0 1]
[0 2]
[1 0]
[1 1]
[1 2]
[2 3]
[3 0]]