Related Articles

# Numpy MaskedArray.compressed() function – Python

• Last Updated : 26 Mar, 2020

`numpy.MaskedArray.compressed()` function return all the non-masked data as a 1-D array.

Return : [ndarray] A new ndarray holding the non-masked data is returned.

Code #1 :

 `# Python program explaining``# numpy.MaskedArray.compressed() function`` ` `# importing numpy as geek  ``# and numpy.ma module as ma ``import` `numpy as geek ``import` `numpy.ma as ma`` ` `arr ``=` `geek.ma.array(geek.arange(``10``), mask ``=``[``0``]``*``6` `+` `[``1``]``*``4``)``gfg ``=` `arr.compressed()`` ` `print``(gfg)`

Output :

```[0 1 2 3 4 5]
```

Code #2 :

 `# Python program explaining``# numpy.MaskedArray.compressed() function`` ` `# importing numpy as geek  ``# and numpy.ma module as ma ``import` `numpy as geek ``import` `numpy.ma as ma`` ` `arr ``=` `geek.ma.array(geek.arange(``7``), mask ``=``[``0``]``*``4` `+` `[``1``]``*``3``)``gfg ``=` `arr.compressed()`` ` `print``(gfg)`

Output :

```[0 1 2 3]
```

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up