numby.bitwise_and.reduce的ufunc.reduce
似乎表现不正常......我滥用它了吗?numpy.bitwise_and.reduce行为意外?
>>> 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'
的reduce()
结果应该是accumulate()
的最后一个值,它不是。我在这里错过了什么?
就目前而言,我可以解决使用德摩根的身份(交换或与AND和反相输入端和输出):
>>> ~np.bitwise_or.reduce(np.invert(x))
17
从版本1.12.0开始,您应该看到'np.bitwise_and'的标识的正确值(-1)。参见[PR#7373](https://github.com/numpy/numpy/pull/7373)。顺便说一下,非常酷的解决方法! –