Python:numpy array 增加,刪除,查找元素索引

import numpy as np

a = np.array([1,2,3,4,5,6])
b = np.array([1,2,3])
c = np.hstack((a,b))

print(c)
print(c.shape)
print(a)
for item in b:
    index = np.where(a==item)
    np.delete(a,index)
print(a)

d =np.delete(a,b)
print(d)
print(a)
e = np.delete(a,[1,2,3])
print(e)
# 獲取元素在類array中的位置索引------以上兩個好像沒什麼不一樣
index = [np.argwhere(a == item)[0][0] for item in b]
print(index)

index1 = [np.where(a == item)[0][0] for item in b]
print(index1)

抱歉!時間有限沒寫詳細!!!

不懂的請留言~~~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章