import numpy as np
a = np.array([1,2,3,-1,-2,9])
where 的条件索引使用:
c = np.where(a==3)
print(c) # tuble
print(c[0])
结果:
ss = np.where(a>=1)
ss_value = a[ss]
print(ss[0]) # 对应的索引
print(ss_value) # 索引对应的值
结果:
在原数组中修改值:
a[a>0] = 0 # 在原数组上进行修改
print("change:",a)
结果: