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)。順便說一下,非常酷的解決方法! –