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 数组x和一个整数数组y,我想做一些相当于:
x
y
z = np.array(x[i] for i in y)
是否有一个 Numpy 函数/方法可以有效地执行此操作而无需转换回列表?
如果y包含对 有效的索引x,则:
z = x[y] >>> import numpy as np >>> x = np.arange(100) >>> y = np.array([1, 27, 36, 98]) >>> x[y] array([ 1, 27, 36, 98])