Skip to content

Quantity issue with np.ma.std and np.ma.var #10792

@larrybradley

Description

@larrybradley

Just ran across this puzzling behavior with np.ma.std and np.ma.var with Quantity inputs:

>>> import numpy as np
>>> import astropy.units as u
>>> a = np.arange(5.) << u.km
>>> np.std(a)
1.4142136 km
>>> np.ma.std(a)  # returns wrong unit!
1.4142136 km(1/2)

>>> np.var(a)
2.0 km2
>>> np.ma.var(a)  # returns wrong unit!
2.0 km

np.ma.mean works fine:

>>> np.mean(a)
2 km
>>> np.ma.mean(a)
2 km

Is this an upstream bug in numpy?
@mhvk

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions