python - What is the difference between "|" and "or"? -
this question has answer here:
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
Post a Comment