[Numpy-discussion] mean of empty sequence gives nan

Robert Kern robert.kern@gmail....
Mon Sep 27 17:55:57 CDT 2010


On Mon, Sep 27, 2010 at 17:51, Peter Butterworth <butterw@gmail.com> wrote:
> In numpy 1.5.0, I got the following for mean of an empty sequence (or array):
>
> In [21]: mean([])
> Warning: invalid value encountered in double_scalars
> Out[21]: nan
>
> Is this behaviour expected ?

np.sum([]) / len([]) -> 0.0 / 0 -> nan, so yes.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the NumPy-Discussion mailing list