如果我有一个 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 操作?从这里我尝试了
np.bitwise_xor.reduce(a)
但它说TypeError: No loop matching the specified signature and casting was found for ufunc bitwise_xor
您需要将数组转换为某种整数类型
np.bitwise_xor.reduce(np.array([0.0, 1.0, 2.0, 3.0]).astype(np.int32))
-> 0