1

I could not apply bool values into given data:

import numpy as np

bool_values = np.array([False, False, True, False, True])
data = np.array([[11.0, 22.0, 0.0, 44.0, 55.0],
                 [10.0, 20.0, 30.0, 40.0, 50.0]])

expected_answer = [[0,55], [30,50]]

I tried it as:

expected_answer = data[bool_values]
2
  • You mean [0.0, 55] right? Commented Jun 22, 2015 at 14:32
  • Aha yes, now corrected Commented Jun 22, 2015 at 14:33

1 Answer 1

1

I think you wanted to do this:

In [28]:
bool_values = np.array([False, False, True, False, True])
data = np.array([[11.0, 22.0, 0.0, 44.0, 55.0],
 [10.0, 20.0, 30.0, 40.0, 50.0]])
data[:,bool_values]

Out[28]:
array([[  0.,  55.],
       [ 30.,  50.]])

The above applies the mask to every row

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

Comments

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.