Einstein summation (numpy.einsum) of boolean arrays in numpy doesn't produce expected results. Numpy.einsum function does logical operations on boolean arrays, which is questionable in the numeric contexts.
# summation of a boolean numpy array
x = numpy.array([True, False, True])
print(numpy.sum(x))
# output: 2
print(numpy.einsum('i->', x))
# output: True
For a boolean array x = [True, False, True], I expect that the summation of x is 2, and the result should not depend on the particular choice of the function. However, numpy.sum gave 2, and numpy.einsum gave True.
I am not sure whether I misunderstood something or there is some problem with my code. Any help is appreciated.
[email protected]([True,True,True])
produces a booleanTrue
as well. – hpauljnp.array([True, False])**np.array([True])
,np.array([True, False])/np.array([True])
, andnp.array([True, False])*np.array([True])
. I think the question is too subjective – yuyangtj