我有一个 float 数组(大小为 9300),以及另一个整数数组(大小为 2600),其中包含第一个数组的索引。我试图根据第二个数组中的索引获取第一个数组中的值。示例:
index 1st_array
0 12.00
1 3.89
2 24.20
3 34.60
index 2nd_array
0 0
1 2
输出:
index 3nd_array
0 12.00
1 24.20
编辑:这些实际上是 numpy 数组:
a1 = np.array([12.00, 3.89, 24.20, 34.60])
a2 = np.array([0, 2])
最佳答案
import numpy as np
arr1 = np.array([12.00, 3.89, 24.20, 34.60])
arr2 = np.array([0, 2])
print(arr1[arr2])
打印
[12. 24.2]
关于python - 如何使用另一个数组和值的索引来获取数组中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71977134/