Numpy array mask comparison operator

I was going through the “Numpy exercises.ipynb” file for practice and I got to the following problem:
##Given the X numpy array, get numbers equal to 2 or 10¶
X = np.array([-1, 2, 0, -4, 5, 6, 0, 0, -9, 10])

I have the solution but I was wondering why I was not able to use “or” and instead had to use “|” in my solution?

Thanks!

Hi,

When using Numpy, & and | have to be used instead of ‘or’ and ‘and’ when combining multiple logical statements. Otherwise you get a ValueError. That are the rules of numpy!

2 Likes

Thank you for your quick response!

1 Like

You are welcome!

Happy coding and pythoning!