Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 numpy 数组向量,我想根据索引获取一个子集:
import numpy as np input=np.array([1,2,3,4,5,6,7,8,9,10]) index=np.array([0,1,0,0,0,0,1,0,0,1])
什么是输出输出= [2,7,10]的pythonic方法?
output = input[index.astype(np.bool)]
或者
output = input[np.where(index)[0]]