Closed
Description
This strange behavior came up in pandas-dev/pandas#19813:
In [23]: np.array([], dtype=object).sum()
Out[23]: False
In [26]: np.array([], dtype=object).prod()
Out[26]: True
It's almost as if NumPy picks a dtype at random (e.g., bool in this case) to use for computing the result. A more obviously and likely more consistent choice would be to use the identities for the appropriate ufuncs (i.e., np.add.identity
and np.mul.identity
), which are the integers 0
and 1
, respectively.
Metadata
Metadata
Assignees
Labels
No labels