[SciPy-user] Bug in scipy.stats skew, kurtosis

joep josef.pktd@gmail....
Thu Oct 2 15:37:20 CDT 2008



On Oct 2, 2:18 pm, "Wes McKinney" <wesmck...@gmail.com> wrote:
> Right now scipy.stats.skew (normal) and scipy.stats.kurtosis (fisher =
> False) applied to a 1-dimensional array return an ndarray of the single
> value with no dimensions.
>
> In [13]: scipy.stats.skew([1,2,3,4,5])
> Out[13]: array(0.0)
>
> I am using Scipy 0.6, but I looked at the latest SVN and this behavior has
> not changed. It's being caused by these lines:
>
> m2 = moment(a, 2, axis)
> m3 = moment(a, 3, axis)
> zero = (m2 == 0)
> vals = np.where(zero, 0, m3 / m2**1.5)
>
> when the condition is not an array in numpy.where, the result is this 0-dim
> array. Not sure if this is a SciPy issue or a numpy issue. If it's a Scipy
> issue I can put in a ticket for this. I am using a workaround for now (check
> if the result of the calc is an array and has no shape, if so cast to float)
> but this seems like a bug.
>
> Thanks,
> Wes
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-u...@scipy.orghttp://projects.scipy.org/mailman/listinfo/scipy-user


In Changeset 4752, this has been changed for pdf, cdf, and so on,
however other methods such as stats still have the same property:

>>> stats.norm.cdf(0.4)
0.65542174161032418

>>> stats.norm.stats(moments='s')
array(0.0)
>>> stats.norm.stats(moments='s')[()]
0.0
>>> stats.norm.stats(moments='s').shape
()

For consistency, it might be better to apply this change to all
methods in scipy.stats that return 0-dim array.

Josef


More information about the SciPy-user mailing list