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

Skip to content

numpy.ma - some statistics operators do not accept tuple axis arguments #8047

@mwtoews

Description

@mwtoews

This is essentially a re-opening of #6844 with examples:

import numpy as np
print(np.__version__)  # 1.11.1
x = np.ma.arange(24)
x.shape = (4, 3, 2)
# e.g. this works
print(np.ma.mean(x, axis=(0,1)))  # [11.0 12.0]
# but it doesn't work with a mask array set
x.mask = x.data > 12

Testing with version 1.11.1, here are the methods that raise TypeError: tuple indices must be integers, not tuple:

  • np.ma.mean(x, axis=(0,1))
  • np.ma.std(x, axis=(0, 1))
  • np.ma.var(x, axis=(0, 1))

This raises a variation TypeError: an integer is required for the axis:

  • np.ma.median(x, axis=(0, 1))

And these methods appear to work, returning a masked array result:

  • np.ma.min(x, axis=(0, 1)) # [0 1]
  • np.ma.max(x, axis=(0, 1)) # [12 11]
  • np.ma.sum(x, axis=(0, 1)) # [42 36]

(are there other operators with a mask= argument?)

I get the same results with NumPy 1.11.1 with Python 2.7 on Windows and Linux.

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