Yar*_*riv 5 numpy vectorization xor
如何使用矢量化方法xor布尔numpy数组的所有元素:即,a_1 xor a_2 xor ... xor a_n?
我更喜欢使用我想的xor ufunc,它是bitwise_xor(或logical_xor):
np.bitwise_xor.reduce(a)
Run Code Online (Sandbox Code Playgroud)
要么:
np.logical_xor.reduce(a)
Run Code Online (Sandbox Code Playgroud)
一个优点是,你不会得到漂浮物的虚假东西.