How can be used multiple filter in the numpy array?

Question:

I am trying to filter some data out from an array

 data = data[data['RotSpeed'] <= ROTOR_SPEED ]
 data = data[data['HorWindV'] <= WIND_SPEED ]

I am wondering if this can be optimized by combining the two filter?

Asked By: Mokus

||

Answers:

You can intersect two filters with the & operator:

data = data[(data['RotSpeed'] <= ROTOR_SPEED) & (data['HorWindV'] <= WIND_SPEED)]

Or union two conditions with the | operator:

data = data[(data['RotSpeed'] <= ROTOR_SPEED) | (data['HorWindV'] <= WIND_SPEED)]

make sure to use parentheses around the field and the filter placed for it

It is unlikely to be much of an optimization though.

Answered By: wim
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.