[英]Skipping specific indices in an array (or addressing intervals of indices)
我有一個數組,我想通過忽略其中的一些來解決它的特定索引。 可能這是最糟糕的方法:
import numpy as np
a=np.arange(15)
b=np.append(np.append(a[0:6],a[9:10]),a[13:15])
print b
有一種解決數組索引間隔的聰明方法嗎?
布爾索引?
In [30]:
a[(np.indices(a.shape)!=7).flatten()]
Out[30]:
array([0, 1, 2, 3, 4, 5, 6, 8, 9])
In [35]:
a[~np.in1d(np.indices(a.shape), (7,9))]
Out[35]:
array([0, 1, 2, 3, 4, 5, 6, 8])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.