我正在尝试找出用numpy排除索引的最佳方法,这是所需的行为:
import numpy as np
a = np.random.randint(0,10,size=10)
print(a)
def fun(x,xs):
print(x,xs) #do some stuff
for i in range(a.shape[0]):
fun(a[i],a[np.arange(a.shape[0]) != i]) #this is all I can think of,but its horrid!
有没有更好,更有效的方法?
编辑:为澄清起见,希望这个问题会更加清楚:
我有一个数组,并且我想要一个在中间中缺少1个或多个元素的视图,例如a = [1,2,3,4,5,...]
至a = [1,...]
。根据{{3}},花哨的索引编制/蒙版制作了数组的副本,我想避免这种情况,并避免创建大型索引数组。预先感谢您的帮助!