我有一个像这样的numpy数组:

a = [0,88,26,3,48,85,65,16,97,83,91]

如何一步一步获取特定索引位置的值?例如:
ind_pos = [1,5,7]

结果应为:
[88,85,16]

最佳答案

只需使用ind_pos进行索引

ind_pos = [1,5,7]
print (a[ind_pos])
[88 85 16]


In [55]: a = [0,88,26,3,48,85,65,16,97,83,91]

In [56]: import numpy as np

In [57]: arr = np.array(a)

In [58]: ind_pos = [1,5,7]

In [59]: arr[ind_pos]
Out[59]: array([88, 85, 16])

关于python - Python:如何在某些索引位置获取数组的值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25201438/

10-10 14:59