MaskedNDArray

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

Bases: astropy.utils.masked.Masked, numpy.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])

Return indices of the maximum values along the given axis.

argmin([axis, out])

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])

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])

Rearranges the elements in the array in such a way that the value of the element in kth position is in the position it would be in a sorted array.

repeat(repeats[, axis])

Repeat elements of an array.

sort([axis, kind, order])

Sort an array in-place.

std([axis, dtype, out, ddof, keepdims, where])

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, where])

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=False, *, where=True)[source]

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=False, *, where=True)[source]

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)[source]

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)[source]

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)[source]

Returns the indices that would partition this array.

Refer to numpy.argpartition for full documentation.

New in version 1.8.0.

See also

numpy.argpartition

equivalent function

argsort(axis=- 1, kind=None, order=None)[source]

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
axisint or None, optional

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

kindstr or None, ignored.

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

orderstr or 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.

Returns
index_arrayndarray, 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')[source]

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)[source]

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)[source]

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)[source]

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)[source]

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=False)[source]

Create an instance from unmasked data and a mask.

max(axis=None, out=None, keepdims=False, initial=<no value>, where=True)[source]

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=False, *, where=True)[source]

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=False, initial=<no value>, where=True)[source]

Return the minimum along a given axis.

Refer to numpy.amin for full documentation.

See also

numpy.amin

equivalent function

nonzero()[source]

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)[source]

Rearranges the elements in the array in such a way that the value of the element in kth position is in the position it would be in a sorted array. All elements smaller than the kth element are moved before this element and all equal or greater are moved behind it. The ordering of the elements in the two partitions is undefined.

New in version 1.8.0.

Parameters
kthint or sequence of 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.

axisint, optional

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

kind{‘introselect’}, optional

Selection algorithm. Default is ‘introselect’.

orderstr or list of 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 parititioned copy of an array.

argpartition

Indirect partition.

sort

Full sort.

Notes

See np.partition for notes on the different algorithms.

Examples

>>> a = np.array([3, 4, 2, 1])
>>> a.partition(3)
>>> a
array([2, 1, 3, 4])
>>> a.partition((1, 3))
>>> a
array([1, 2, 3, 4])
repeat(repeats, axis=None)[source]

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)[source]

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

std(axis=None, dtype=None, out=None, ddof=0, keepdims=False, *, where=True)[source]

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)[source]

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=False, *, where=True)[source]

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)[source]

New view of the masked array.

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