将(2d)numpy数组的所有值异或在一起

af7jpaap  于 9个月前  发布在  其他
关注(0)|答案(1)|浏览(73)

如果我有一个2d numpy数组(数据不一定是连续的,但例如)

[[0. 1. 2. 3.]
 [4. 5. 6. 7.]
 [8. 9. 10. 11.]]

字符串
如何计算0^1^2^3^4^5^6^7^8^9^10?
我想我可以将它展平,然后使用np.vectorize(),但我想知道是否可以直接使用numpy操作?从here我尝试np.bitwise_xor.reduce(a),但它显示TypeError: No loop matching the specified signature and casting was found for ufunc bitwise_xor

tvz2xvvm

tvz2xvvm1#

你需要把数组转换成整型

np.bitwise_xor.reduce(np.array([0.0, 1.0, 2.0, 3.0]).astype(np.int32))

字符串
-> 0

相关问题