numpy / numpy/numpy

Masked array dimensions added when apply mask value?

Open
#15,002 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

00 - Bug 01 - Enhancement component: numpy.ma
Dominant language
Python
Stars
32.8k
Forks
12.8k
Avg merge
1d 7h
Merged PRs (30d)
197

Description

When i apply mask generated by ma.zeros on the zeros matrix, i have an behaviour which i don't understand.

Reproducing code example:
import numpy as np
a = np.ma.zeros(5)
# add a dimensions
print(a[~a.mask])
# Seem work correctly
print(a[a.mask])
# But when we check dimensions??:
print(a[a.mask].shape)
Result
print(a[~a.mask])
[[0. 0. 0. 0. 0.]]
print(a[a.mask])
[]
print(a[a.mask].shape)
(0, 5)
Numpy/Python version information:

1.16.5 3.7.4 (default, Aug 13 2019, 20:35:49)
[GCC 7.3.0]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the provided Python reproduction with NumPy masked arrays and inspect the shapes and values produced by each indexing expression. Trace the masked-array indexing behavior, then establish whether the reported shape is expected; done means the behavior is corrected or clearly explained with appropriate coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.