The ufunc.reduce
for numpy.bitwise_and.reduce does not appear to behave properly... am I misusing it?
>>> import numpy as np
>>> x = [0x211f,0x1013,0x1111]
>>> np.bitwise_or.accumulate(x)
array([ 8479, 12575, 12575])
>>> np.bitwise_and.accumulate(x)
array([8479, 19, 17])
>>> '%04x' % np.bitwise_or.reduce(x)
'311f'
>>> '%04x' % np.bitwise_and.reduce(x)
'0001'
The result of reduce()
should be the last value of accumulate()
and it's not. What am I missing here?
For the moment, I can work around by using DeMorgan's identity (swapping OR and AND, and inverting input and output):
>>> ~np.bitwise_or.reduce(np.invert(x))
17