- np.where(condition):找到满足条件的数组下标值
# 首先我们定义一个长为12,范围为[1, 100]的随机整数数组。
array = np.random.randint(1, 101, size=12)
# 找到满足数组中元素大于50的array数组下标。
pos = np.where(array > 50)
"""===== output ====
# 得到下标为第2个、3、5、7、9个元素。另外注意np.where返回的是元组类型(即tuple)。
pos = (array([2, 3, 5, 7, 9]),)
"""
# 输出一下array这些下标的值
print(array[pos])
"""===== output ====
array([89, 89, 81, 59, 85])
"""