0
import numpy as np

arr1= np.array([10,20,30,40,50])
arr2= np.array([False, False,  True,  True,  True])

result=arr1[arr2] #[30 40 50]

Having hard time to grasp this. When another numpy array is passed to an existing numpy array, all elements multiplied?

2

1 Answer 1

3

You're indexing a numpy array by another array, rather than passing an array to another array. In your case, since you're using a boolean index, it's creating a mask, and only returning the values of arr1 where arr2 is True.

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.