2

Is there a numpy function (or algorithm) that only returns the items of an array depending on and and-function of the values of two other boolean arrays.

E.g.

>>> b1 = numpy.array([False, False, True, True , True])
>>> b2 = numpy.array([True , False, True, False, True])
>>> v  = numpy.array([2    , 4    , 6   , 8,     10  ])

Then the function should return:

numpy.array([6, 10])

Because 6 and 10 are the values where both the corresponding b1 and b2 values are True.

Edited according accepted answer below:

>>> v[b1 & b2]
array([ 6, 10])

1 Answer 1

4
v[b1 & b2]

will do the trick.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you ... this is the second answer of less than 10 characters with a perfect solution for my problem :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.