Thanks to visit codestin.com
Credit goes to github.com

Skip to content

variance nonzero for constant array #9631

Open
@gerritholl

Description

@gerritholl

NumPy may give a nonzero variance (and thus standard deviation) for a constant array. This may be due to loss of numerical precision, but Pythons builtin variance routine gives the correct 0 answer, so clearly it's a preventable loss:

In [45]: x = [6715266981.538051]*10

In [46]: statistics.variance(x)
Out[46]: 0.0

In [47]: numpy.array(x).var()
Out[47]: 9.0949470177292824e-13

I think it would be highly desirable if x.std() and x.var() for a constant array could be assumed to be exactly identical to zero. I'm aware one should not compare floating point numbers but zero is a bit of a special case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions