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

ma.compressed(x)

[source]

#

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

This function is equivalent to calling the “compressed” method of a

ma.MaskedArray

, see

ma.MaskedArray.compressed

for details.

Examples

>>> importnumpyasnpCreate an array with negative values masked:

>>> importnumpyasnp>>> x=np.array([[1,-1,0],[2,-1,3],[7,4,-1]])>>> masked_x=np.ma.masked_array(x,mask=x<0)>>> masked_xmasked_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])