Skip to main content
`Ctrl`+`K`

# MaskedNDArray

class astropy.utils.masked.MaskedNDArray(*args, mask=None, **kwargs)

  Bases: `Masked`, `ndarray`

  Masked version of ndarray.

  Except for the ability to pass in a `mask`, parameters are as for `numpy.ndarray`.

  Get data class instance from arguments and then set mask.

  Attributes Summary

  `flat` | A 1-D iterator over the Masked array.
  `info` | Container for meta information like name, description, format.
  `shape` | The shape of the data and the mask.
  `unmasked` | The unmasked values.

  Methods Summary

  `all`([axis, out, keepdims, where]) | Returns True if all elements evaluate to True.
  `any`([axis, out, keepdims, where]) | Returns True if any of the elements of `a` evaluate to True.
  `argmax`([axis, out, keepdims]) | Return indices of the maximum values along the given axis.
  `argmin`([axis, out, keepdims]) | Return indices of the minimum values along the given axis.
  `argpartition`(kth[, axis, kind, order]) | Returns the indices that would partition this array.
  `argsort`([axis, kind, order, stable]) | Returns the indices that would sort an array.
  `choose`(choices[, out, mode]) | Use an index array to construct a new array from a set of choices.
  `clip`([min, max, out]) | Return an array whose values are limited to `[min, max]`.
  `compress`(condition[, axis, out]) | Return selected slices of this array along given axis.
  `cumprod`([axis, dtype, out]) | Return the cumulative product of the elements along the given axis.
  `cumsum`([axis, dtype, out]) | Return the cumulative sum of the elements along the given axis.
  `from_unmasked`(data[, mask, copy]) | Create an instance from unmasked data and a mask.
  `max`([axis, out, keepdims, initial, where]) | Return the maximum along a given axis.
  `mean`([axis, dtype, out, keepdims, where]) | Returns the average of the array elements along given axis.
  `min`([axis, out, keepdims, initial, where]) | Return the minimum along a given axis.
  `nonzero`() | Return the indices of the elements that are non-zero.
  `partition`(kth[, axis, kind, order]) | Partially sorts the elements in the array in such a way that the value of the element in k-th position is in the position it would be in a sorted array.
  `ptp`([axis, out]) |
  `repeat`(repeats[, axis]) | Repeat elements of an array.
  `sort`([axis, kind, order, stable]) | Sort an array in-place.
  `std`([axis, dtype, out, ddof, keepdims, ...]) | Returns the standard deviation of the array elements along given axis.
  `trace`([offset, axis1, axis2, dtype, out]) | Return the sum along diagonals of the array.
  `var`([axis, dtype, out, ddof, keepdims, ...]) | Returns the variance of the array elements, along given axis.
  `view`([dtype, type]) | New view of the masked array.

  Attributes Documentation

  flat

    A 1-D iterator over the Masked array.

    This returns a `MaskedIterator` instance, which behaves the same as the `flatiter` instance returned by `flat`, and is similar to Python’s built-in iterator, except that it also allows assignment.

  info

    Container for meta information like name, description, format.

  shape

    The shape of the data and the mask.

    Usually used to get the current shape of an array, but may also be used to reshape the array in-place by assigning a tuple of array dimensions to it. As with `numpy.reshape`, one of the new shape dimensions can be -1, in which case its value is inferred from the size of the array and the remaining dimensions.

    Raises:
      `AttributeError`

        If a copy is required, of either the data or the mask.

  unmasked

  Methods Documentation

  all(axis=None, out=None, *, keepdims=<no value>, where=<no value>)

    Returns True if all elements evaluate to True.

    Refer to `numpy.all` for full documentation.

    See also

    `numpy.all`

      equivalent function

  any(axis=None, out=None, *, keepdims=<no value>, where=<no value>)

    Returns True if any of the elements of `a` evaluate to True.

    Refer to `numpy.any` for full documentation.

    See also

    `numpy.any`

      equivalent function

  argmax(axis=None, out=None, *, keepdims=False)

    Return indices of the maximum values along the given axis.

    Refer to `numpy.argmax` for full documentation.

    See also

    `numpy.argmax`

      equivalent function

  argmin(axis=None, out=None, *, keepdims=False)

    Return indices of the minimum values along the given axis.

    Refer to `numpy.argmin` for detailed documentation.

    See also

    `numpy.argmin`

      equivalent function

  argpartition(kth, axis=-1, kind='introselect', order=None)

    Returns the indices that would partition this array.

    Refer to `numpy.argpartition` for full documentation.

    See also

    `numpy.argpartition`

      equivalent function

  argsort(axis=-1, kind=None, order=None, *, stable=None)

    Returns the indices that would sort an array.

    Perform an indirect sort along the given axis on both the array and the mask, with masked items being sorted to the end.

    Parameters:
      axis `python:int` or `python:None`, optional

        Axis along which to sort. The default is -1 (the last axis). If None, the flattened array is used.

      kind `python:str` or `python:None`, ignored.

        The kind of sort. Present only to allow subclasses to work.

      order `python:str` or `python:list` of str.

        For an array with fields defined, the fields to compare first, second, etc. A single field can be specified as a string, and not all fields need be specified, but unspecified fields will still be used, in dtype order, to break ties.

      stable: bool, keyword-only, ignored

        Sort stability. Present only to allow subclasses to work.

    Returns:
      index_array `ndarray`, `python:int`

        Array of indices that sorts along the specified `axis`. Use `np.take_along_axis(self, index_array, axis=axis)` to obtain the sorted array.

  choose(choices, out=None, mode='raise')

    Use an index array to construct a new array from a set of choices.

    Refer to `numpy.choose` for full documentation.

    See also

    `numpy.choose`

      equivalent function

  clip(min=None, max=None, out=None, **kwargs)

    Return an array whose values are limited to `[min, max]`.

    Like `clip`, but any masked values in `min` and `max` are ignored for clipping. The mask of the input array is propagated.

  compress(condition, axis=None, out=None)

    Return selected slices of this array along given axis.

    Refer to `numpy.compress` for full documentation.

    See also

    `numpy.compress`

      equivalent function

  cumprod(axis=None, dtype=None, out=None)

    Return the cumulative product of the elements along the given axis.

    Refer to `numpy.cumprod` for full documentation.

    See also

    `numpy.cumprod`

      equivalent function

  cumsum(axis=None, dtype=None, out=None)

    Return the cumulative sum of the elements along the given axis.

    Refer to `numpy.cumsum` for full documentation.

    See also

    `numpy.cumsum`

      equivalent function

  classmethod from_unmasked(data, mask=None, copy=None)

    Create an instance from unmasked data and a mask.

  max(axis=None, out=None, *, keepdims=<no value>, initial=<no value>, where=<no value>)

    Return the maximum along a given axis.

    Refer to `numpy.amax` for full documentation.

    See also

    `numpy.amax`

      equivalent function

  mean(axis=None, dtype=None, out=None, *, keepdims=<no value>, where=<no value>)

    Returns the average of the array elements along given axis.

    Refer to `numpy.mean` for full documentation.

    See also

    `numpy.mean`

      equivalent function

  min(axis=None, out=None, *, keepdims=<no value>, initial=<no value>, where=<no value>)

    Return the minimum along a given axis.

    Refer to `numpy.amin` for full documentation.

    See also

    `numpy.amin`

      equivalent function

  nonzero()

    Return the indices of the elements that are non-zero.

    Refer to `numpy.nonzero` for full documentation.

    See also

    `numpy.nonzero`

      equivalent function

  partition(kth, axis=-1, kind='introselect', order=None)

    Partially sorts the elements in the array in such a way that the value of the element in k-th position is in the position it would be in a sorted array. In the output array, all elements smaller than the k-th element are located to the left of this element and all equal or greater are located to its right. The ordering of the elements in the two partitions on the either side of the k-th element in the output array is undefined.

    Parameters:
      kth `python:int` or python:sequence of `python:int`

        Element index to partition by. The kth element value will be in its final sorted position and all smaller elements will be moved before it and all equal or greater elements behind it. The order of all elements in the partitions is undefined. If provided with a sequence of kth it will partition all elements indexed by kth of them into their sorted position at once.

        Deprecated since version 1.22.0: Passing booleans as index is deprecated.

      axis `python:int`, optional

        Axis along which to sort. Default is -1, which means sort along the last axis.

      kind{‘introselect’}, optional

        Selection algorithm. Default is ‘introselect’.

      order `python:str` or `python:list` of `python:str`, optional

        When `a` is an array with fields defined, this argument specifies which fields to compare first, second, etc. A single field can be specified as a string, and not all fields need to be specified, but unspecified fields will still be used, in the order in which they come up in the dtype, to break ties.

    See also

    `numpy.partition`

      Return a partitioned copy of an array.

    `argpartition`

      Indirect partition.

    `sort`

      Full sort.

    Notes

    See `np.partition` for notes on the different algorithms.

    Examples

        >>> import numpy as np
        >>> a = np.array([3, 4, 2, 1])
        >>> a.partition(3)
        >>> a
        array([2, 1, 3, 4]) # may vary

        >>> a.partition((1, 3))
        >>> a
        array([1, 2, 3, 4])

  ptp(axis=None, out=None, **kwargs)
  repeat(repeats, axis=None)

    Repeat elements of an array.

    Refer to `numpy.repeat` for full documentation.

    See also

    `numpy.repeat`

      equivalent function

  sort(axis=-1, kind=None, order=None, *, stable=False)

    Sort an array in-place. Refer to `numpy.sort` for full documentation.

    Notes

    Masked items will be sorted to the end. The implementation is via `numpy.lexsort` and thus ignores the `kind` and `stable` arguments; they are present only so that subclasses can pass them on.

  std(axis=None, dtype=None, out=None, ddof=0, *, keepdims=<no value>, where=<no value>, mean=<no value>)

    Returns the standard deviation of the array elements along given axis.

    Refer to `numpy.std` for full documentation.

    See also

    `numpy.std`

      equivalent function

  trace(offset=0, axis1=0, axis2=1, dtype=None, out=None)

    Return the sum along diagonals of the array.

    Refer to `numpy.trace` for full documentation.

    See also

    `numpy.trace`

      equivalent function

  var(axis=None, dtype=None, out=None, ddof=0, *, keepdims=<no value>, where=<no value>, mean=<no value>)

    Returns the variance of the array elements, along given axis.

    Refer to `numpy.var` for full documentation.

    See also

    `numpy.var`

      equivalent function

  view(dtype=None, type=None)

    New view of the masked array.

    Like `numpy.ndarray.view`, but always returning a masked array subclass.