numpy.ma.masked_all_like#

ma.masked_all_like(arr)[source]#

Empty masked array with the properties of an existing array.

Return an empty masked array of the same shape and dtype as the array arr, where all the data are masked.

Parameters:
arrndarray

An array describing the shape and dtype of the required MaskedArray.

Returns:
aMaskedArray

A masked array with all data masked.

Raises:
AttributeError

If arr doesn’t have a shape attribute (i.e. not an ndarray)

See also

masked_all

Empty masked array with all elements masked.

Notes

Unlike other masked array creation functions (e.g. numpy.ma.zeros_like, numpy.ma.ones_like, numpy.ma.full_like), masked_all_like does not initialize the values of the array, and may therefore be marginally faster. However, the values stored in the newly allocated array are arbitrary. For reproducible behavior, be sure to set each element of the array before reading.

Examples

>>> arr = np.zeros((2, 3), dtype=np.float32)
>>> arr
array([[0., 0., 0.],
       [0., 0., 0.]], dtype=float32)
>>> np.ma.masked_all_like(arr)
masked_array(
  data=[[--, --, --],
        [--, --, --]],
  mask=[[ True,  True,  True],
        [ True,  True,  True]],
  fill_value=np.float64(1e+20),
  dtype=float32)

The dtype of the masked array matches the dtype of arr.

>>> arr.dtype
dtype('float32')
>>> np.ma.masked_all_like(arr).dtype
dtype('float32')