Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a numpy structured array with a dtype such as:

A = numpy.empty(10, dtype=([('segment', '<i8'), ('material', '<i8'), ('rxN', '<i8')]))

I know I can create a mask such as:

A[A['segment'] == 42] = ...

Is there a way to create a mask on multiple columns? For example (I know this doesn't work, but I wish it did):

A[A['segment'] == 42 and A['material'] == 5] = ...
share|improve this question

1 Answer 1

up vote 6 down vote accepted

You can use the & operator instead of and:

A[(A['segment'] == 42) & (A['material'] == 5)]

Note that extra parantheses are required.

share|improve this answer
    
Simple, I love it. Thanks! –  Jeremy Jul 22 '11 at 16:04

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.