[Numpy-discussion] subtract.reduce behavior

Pauli Virtanen pav@iki...
Fri Jul 23 09:37:54 CDT 2010


Fri, 23 Jul 2010 10:29:47 -0400, Alan G Isaac wrote:
[clip]
>          >>> np.subtract.reduce([])
>          0.0
> 
> Getting a right identity for an empty array is surprising. Matching
> Python's behavior (raising a TypeError) seems desirable. (?)

I don't think matching Python's behavior is a sufficient argument for a 
change. As far as I see, it'd mostly cause unnecessary breakage, with no 
significant gain.

Besides, it's rather common to define

	sum_{z in Z} z = 0
	prod_{z in Z} z = 1

if Z is an empty set -- this can then be extended to other reduction 
operations. Note that changing reduce behavior would require us to 
special-case the above two operations.

-- 
Pauli Virtanen



More information about the NumPy-Discussion mailing list