使用 Python 中单个列表中的已知元素打印多个列表中的相应元素

Printing corresponding elements from multiple lists by using known element from a single list in Python

我有 4 个非常大的数组,a、b、c 和 d 大小相同。我在 'a' 中 selected 特定元素,我需要 b、c 和 d 中的相应元素(即,如果我 select 来自 'a' 的元素想要这些元素来自具有相同索引的其他数组)。

但是,我只知道我感兴趣的元素,而不是它们的索引,因为它们是经过分析 selected 的。

我试图进入数组找到我感兴趣的元素,然后我需要一些能够检索该元素的索引。

data = pl.loadtxt('mydata1.cat')
i = np.array(5448)
a = data[:,3]
b = data[:,9]
c = data[:,10]
d = data[:,11]
j = 34.44
for h in a[i]:
    if h == j:
    print a[i] , b[i], c[i], d[i]
else:
    print "no!"

看起来你可以使用 numpy where function:

//Set i to be index of h in data
i = numpy.where(data==h)