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

664 Views Asked by At

I have 4 very large arrays, a, b, c, and d of the same size. I have selected specific elements in 'a', and I need the corresponding elements from b, c, and d (i.e. if I select an element from 'a' want the elements from the other arrays that have the same index).

However, I only know the the elements that I am interested in, not their indices because they were analytically selected.

I am trying to go into the array find the element I am interested in, then some I need to be able to retrieve the index of that element.

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!"
1

There are 1 best solutions below

0
On BEST ANSWER

Looks like you can use the numpy where function:

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