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)

抱歉!时间有限没写详细!!!

不懂的请留言~~~

你可能感兴趣的:(Python学习)