What is the numpy.ma.masked_all() function in Python?
Overview
The ma.masked_all() function in Python is used to empty a masked array of the given shape and data type with all elements masked.
Syntax
ma.masked_all(shape, dtype=<class 'float'>)
Parameters
The ma.masked_all() function takes the following parameter values:
shape: This represents the shape of the output masked array.dtype: This represents the data type of the output array. This is optional.
Return value
The ma.masked_all() function returns a masked array where all elements are masked.
Example
import numpy as npimport numpy.ma as ma# implementing the `ma.masked_all()` functionmyarray = ma.masked_all((2,3), dtype=np.float)# printing the arrayprint(myarray)
Explanation
- Line 1–2: We import the necessary modules and libraries.
- Line 5: We implement the
ma.masked_all()function using a shape of2by3and afloatdtypefor the output array. The result is stored inmyarray. - Line 8: We print the masked array
myarray.