我有一个numpy像这样的数组:
a = np.arange(30)
Run Code Online (Sandbox Code Playgroud)
我知道我可以indices=[2,3,4]使用例如花式索引来替换位置上的值:
a[indices] = 999
Run Code Online (Sandbox Code Playgroud)
但是如何替换不在的位置的值indices?会是这样的吗?
a[ not in indices ] = 888
Run Code Online (Sandbox Code Playgroud)
谢谢!
说我有一些长数组和一系列指数.如何选择除那些指数以外的所有内容?我找到了一个解决方案,但它并不优雅:
import numpy as np
x = np.array([0,10,20,30,40,50,60])
exclude = [1, 3, 5]
print x[list(set(range(len(x))) - set(exclude))]
Run Code Online (Sandbox Code Playgroud)