numpy.ma.MaskedArray.compressed — NumPy v2.6.dev0 Manual

Learn | NEPs | User Guide | API reference | Building from source | Development | Release notes | NumPy’s module structure | Array objects | Universal functions (ufunc) | Routines and objects by topic | Constants | Bit-wise operations | String functionality | Data type routines | Floating point error handling | Discrete Fourier Transform | Input and output | Linear algebra | Logic functions | Masked array operations | Mathematical functions | Miscellaneous routines | Random sampling | Set routines | Sorting, searching, and counting | Test support | Window functions

method

ma.MaskedArray.compressed()

[source]

#

Return all the non-masked data as a 1-D array.

Returns:datandarrayA new

ndarray

holding the non-masked data is returned.

Notes

The result is not a MaskedArray!

Examples

>>> importnumpyasnp>>> x=np.ma.array(np.arange(5),mask=[0]*2+[1]*3)>>> x.compressed()array([0, 1])>>> type(x.compressed())<class 'numpy.ndarray'>N-D arrays are compressed to 1-D.

>>> arr=[[1,2],[3,4]]>>> mask=[[1,0],[0,1]]>>> x=np.ma.array(arr,mask=mask)>>> x.compressed()array([2, 3])

1 1