Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

So my problem is I have two parallel arrays

B = np.array([250 , 270, 120, 100 , 200, 300]) A = np.array([1 , 2, 5, 6, 1, 4])

So, if the values in each indices are linked (250 - 1, 270 - 2 , 120 - 5, etc) I want to eliminate any value in the B array that has an even number in the A array.

How would I go along and do that? Any help would be appreciated

share|improve this question

1 Answer 1

>>> b = np.array([250, 270, 120, 100, 200, 300])
>>> a = np.array([1, 2, 5, 6, 1, 4])
>>> b[a % 2 != 0]
array([250, 120, 200])

If array 'a' is longer than array 'b', then I think you'll need to do something like this:

>>> b[a[:len(b)] % 2 != 0]
share|improve this answer
    
thanks! I applied the concept to my code, but I get the error "ValueError: too many boolean indices". What does that mean? – Carl To Mar 30 '12 at 4:27
    
I think it might be because array a is longer than array b. I've updated my answer. – grc Mar 30 '12 at 4:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.