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 np
import numpy.ma as ma
# implementing the `ma.masked_all()` function
myarray = ma.masked_all((2,3), dtype=np.float)
# printing the array
print(myarray)

Explanation

  • Line 1–2: We import the necessary modules and libraries.
  • Line 5: We implement the ma.masked_all() function using a shape of 2 by 3 and a float dtype for the output array. The result is stored in myarray.
  • Line 8: We print the masked array myarray.

Free Resources