[Numpy-discussion] the mean, var, std of empty arrays
sebastian at sipsolutions.net
Thu Nov 22 10:15:54 EST 2012
On Thu, 2012-11-22 at 16:05 +0100, Daπid wrote:
> On Thu, Nov 22, 2012 at 3:54 PM, <josef.pktd at gmail.com> wrote:
> > Why don't operations on empty arrays not return empty arrays?
> Because functions like mean or std are expected to return a scalar.
> Functions that are piecewiese can (and should) return an empty array,
> but not the mean.
I agree, this makes sense, note that:
In : a = np.empty((5,0))
In : a.std(0)
Out: array(, dtype=float64)
In : a.std(1)
/usr/bin/ipython:1: RuntimeWarning: invalid value encountered in divide
Out: array([ nan, nan, nan, nan, nan])
However you are reducing, and with reducing you expect exactly 1 scalar
result (along that dimension).
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
More information about the NumPy-Discussion