[Numpy-discussion] np.bitwise_and.identity
Citi, Luca
lciti at essex.ac.uk
Wed Sep 2 12:11:08 EDT 2009
Hello,
I know I am splitting the hair, but should not
np.bitwise_and.identity be -1 instead of 1?
I mean, something with all the bits set?
I am checking whether all elements of a vector 'v'
have a certain bit 'b' set:
if np.bitwise_and.reduce(v) & (1 << b):
# do something
If v is empty, the expression is true for b==0 and
false otherwise.
In fact np.bitwise_and.identity is 1.
I like being able to use np.bitwise_and.reduce
because it many times faster than (v & (1 << b)).all()
(it does not create the temporary vector).
Of course there are workarounds but I was wondering
if there is a reason for this behaviour.
Best,
Luca
More information about the NumPy-Discussion
mailing list