python - What is the difference between "|" and "or"? -


i using numpy :

in [83]: names = np.array(['bob', 'joe', 'will', 'bob', 'will', 'joe', 'joe'])  in [93]: mask = (names == 'bob') | (names == 'will') 

why can not use "or" instead of "|"?

why give me error when remove pretenses in in[93] ?

valueerror: truth value of array more 1 element ambiguous. use a.any() or a.all()

thanks in advance.

and python's logical-and operator.

| python's bitwise-or operator (not bitwise-and, question might suggest), numpy overrides in order make numpy element-wise-or.

numpy couldn't have overridden and nor or work element-wise, because and , or not overridable in python. therefor, bitwise operators overridden in numpy.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -