summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2020-04-04 22:01:58 +0300
committerGitHub <noreply@github.com>2020-04-04 22:01:58 +0300
commit063b3140ec3792f0420da9f386d8240693213ec9 (patch)
tree6c747b3569735fe89c2b4a57d3d0a5013a78e902 /numpy
parentc67396b805291e1a880084e701f160b21d2b4b1d (diff)
parent3d34de6965b6a8f574e5eb63776904c6ea4b3ab4 (diff)
downloadnumpy-063b3140ec3792f0420da9f386d8240693213ec9.tar.gz
Merge pull request #15749 from panpiort8/masked_array_docs
DOC: document inconsistency between the shape of data and mask in numpy.ma
Diffstat (limited to 'numpy')
-rw-r--r--numpy/ma/core.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 41af5cc70..fa888107f 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -2753,6 +2753,52 @@ class MaskedArray(ndarray):
in any order (either C-, Fortran-contiguous, or even discontiguous),
unless a copy is required, in which case it will be C-contiguous.
+ Examples
+ --------
+
+ The ``mask`` can be initialized with an array of boolean values
+ with the same shape as ``data``.
+
+ >>> data = np.arange(6).reshape((2, 3))
+ >>> np.ma.MaskedArray(data, mask=[[False, True, False],
+ ... [False, False, True]])
+ masked_array(
+ data=[[0, --, 2],
+ [3, 4, --]],
+ mask=[[False, True, False],
+ [False, False, True]],
+ fill_value=999999)
+
+ Alternatively, the ``mask`` can be initialized to homogeneous boolean
+ array with the same shape as ``data`` by passing in a scalar
+ boolean value:
+
+ >>> np.ma.MaskedArray(data, mask=False)
+ masked_array(
+ data=[[0, 1, 2],
+ [3, 4, 5]],
+ mask=[[False, False, False],
+ [False, False, False]],
+ fill_value=999999)
+
+ >>> np.ma.MaskedArray(data, mask=True)
+ masked_array(
+ data=[[--, --, --],
+ [--, --, --]],
+ mask=[[ True, True, True],
+ [ True, True, True]],
+ fill_value=999999,
+ dtype=int64)
+
+ .. note::
+ The recommended practice for initializing ``mask`` with a scalar
+ boolean value is to use ``True``/``False`` rather than
+ ``np.True_``/``np.False_``. The reason is :attr:`nomask`
+ is represented internally as ``np.False_``.
+
+ >>> np.False_ is np.ma.nomask
+ True
+
"""
__array_priority__ = 15