summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorStefanie Molin <24376333+stefmolin@users.noreply.github.com>2023-04-04 09:48:21 -0400
committerGitHub <noreply@github.com>2023-04-04 19:18:21 +0530
commit7f1ce595cee3df09be57abde68e14688516dbe04 (patch)
tree53c5b988164e386b045b2b0420adc2b232a94ecd /numpy
parent9bea0d67002ea789526119bca28a38d9fb62dd37 (diff)
downloadnumpy-7f1ce595cee3df09be57abde68e14688516dbe04.tar.gz
DOC: Add example for np.ma.compressed. (#23426)
* DOC: Add example to np.ma.compressed(). * Update example. * Update core.py
Diffstat (limited to 'numpy')
-rw-r--r--numpy/ma/core.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index dcec82773..7f57985a9 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -7033,6 +7033,29 @@ def compressed(x):
--------
ma.MaskedArray.compressed : Equivalent method.
+ Examples
+ --------
+
+ Create an array with negative values masked:
+
+ >>> import numpy as np
+ >>> x = np.array([[1, -1, 0], [2, -1, 3], [7, 4, -1]])
+ >>> masked_x = np.ma.masked_array(x, mask=x < 0)
+ >>> masked_x
+ masked_array(
+ data=[[1, --, 0],
+ [2, --, 3],
+ [7, 4, --]],
+ mask=[[False, True, False],
+ [False, True, False],
+ [False, False, True]],
+ fill_value=999999)
+
+ Compress the masked array into a 1-D array of non-masked values:
+
+ >>> np.ma.compressed(masked_x)
+ array([1, 0, 2, 3, 7, 4])
+
"""
return asanyarray(x).compressed()