numpy 中的陣列條件索引 where
阿新 • • 發佈:2020-12-27
技術標籤:Numpy,pythonnumpypythonpythonnumpy
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)
結果: