Masked array operations

Constants

methoddescription
ma.MaskTypeopen in new windowalias of numpy.bool_

Creation

From existing data

methoddescription
ma.masked_arrayopen in new windowalias of numpy.ma.core.MaskedArray
ma.arrayopen in new window(data[, dtype, copy, order, mask, …])An array class with possibly masked values.
ma.copyopen in new window(self, *args, **params) a.copy(order=)Return a copy of the array.
ma.frombufferopen in new window(buffer[, dtype, count, offset])Interpret a buffer as a 1-dimensional array.
ma.fromfunctionopen in new window(function, shape, **kwargs)Construct an array by executing a function over each coordinate.
ma.MaskedArray.copyopen in new window([order])Return a copy of the array.

Ones and zeros

methoddescription
ma.emptyopen in new window(shape[, dtype, order])Return a new array of given shape and type, without initializing entries.
ma.empty_likeopen in new window(prototype[, dtype, order, …])Return a new array with the same shape and type as a given array.
ma.masked_allopen in new window(shape[, dtype])Empty masked array with all elements masked.
ma.masked_all_likeopen in new window(arr)Empty masked array with the properties of an existing array.
ma.onesopen in new window(shape[, dtype, order])Return a new array of given shape and type, filled with ones.
ma.zerosopen in new window(shape[, dtype, order])Return a new array of given shape and type, filled with zeros.

Inspecting the array

methoddescription
ma.allopen in new window(self[, axis, out, keepdims])Returns True if all elements evaluate to True.
ma.anyopen in new window(self[, axis, out, keepdims])Returns True if any of the elements of a evaluate to True.
ma.countopen in new window(self[, axis, keepdims])Count the non-masked elements of the array along the given axis.
ma.count_maskedopen in new window(arr[, axis])Count the number of masked elements along the given axis.
ma.getmaskopen in new window(a)Return the mask of a masked array, or nomask.
ma.getmaskarrayopen in new window(arr)Return the mask of a masked array, or full boolean array of False.
ma.getdataopen in new window(a[, subok])Return the data of a masked array as an ndarray.
ma.nonzeroopen in new window(self)Return the indices of unmasked elements that are not zero.
ma.shapeopen in new window(obj)Return the shape of an array.
ma.sizeopen in new window(obj[, axis])Return the number of elements along a given axis.
ma.is_maskedopen in new window(x)Determine whether input has masked values.
ma.is_maskopen in new window(m)Return True if m is a valid, standard mask.
ma.MaskedArray.allopen in new window(self[, axis, out, keepdims])Returns True if all elements evaluate to True.
ma.MaskedArray.anyopen in new window(self[, axis, out, keepdims])Returns True if any of the elements of a evaluate to True.
ma.MaskedArray.countopen in new window(self[, axis, keepdims])Count the non-masked elements of the array along the given axis.
ma.MaskedArray.nonzeroopen in new window(self)Return the indices of unmasked elements that are not zero.
ma.shapeopen in new window(obj)Return the shape of an array.
ma.sizeopen in new window(obj[, axis])Return the number of elements along a given axis.
methoddescription
ma.MaskedArray.dataReturns the underlying data, as a view of the masked array.
ma.MaskedArray.maskCurrent mask.
ma.MaskedArray.recordmaskGet or set the mask of the array if it has no named fields.

Manipulating a MaskedArray

Changing the shape

methoddescription
ma.ravelopen in new window(self[, order])Returns a 1D version of self, as a view.
ma.reshapeopen in new window(a, new_shape[, order])Returns an array containing the same data with a new shape.
ma.resizeopen in new window(x, new_shape)Return a new masked array with the specified size and shape.
ma.MaskedArray.flattenopen in new window([order])Return a copy of the array collapsed into one dimension.
ma.MaskedArray.ravelopen in new window(self[, order])Returns a 1D version of self, as a view.
ma.MaskedArray.reshapeopen in new window(self, *s, **kwargs)Give a new shape to the array without changing its data.
ma.MaskedArray.resizeopen in new window(self, newshape[, …])

Modifying axes

methoddescription
ma.swapaxesopen in new window(self, *args, …)Return a view of the array with axis1 and axis2 interchanged.
ma.transposeopen in new window(a[, axes])Permute the dimensions of an array.
ma.MaskedArray.swapaxesopen in new window(axis1, axis2)Return a view of the array with axis1 and axis2 interchanged.
ma.MaskedArray.transposeopen in new window(*axes)Returns a view of the array with axes transposed.

Changing the number of dimensions

methoddescription
ma.atleast_1dopen in new window(*args, **kwargs)Convert inputs to arrays with at least one dimension.
ma.atleast_2dopen in new window(*args, **kwargs)View inputs as arrays with at least two dimensions.
ma.atleast_3dopen in new window(*args, **kwargs)View inputs as arrays with at least three dimensions.
ma.expand_dimsopen in new window(a, axis)Expand the shape of an array.
ma.squeezeopen in new window(a[, axis])Remove single-dimensional entries from the shape of an array.
ma.MaskedArray.squeezeopen in new window([axis])Remove single-dimensional entries from the shape of a.
ma.stackopen in new window(*args, **kwargs)Join a sequence of arrays along a new axis.
ma.column_stackopen in new window(*args, **kwargs)Stack 1-D arrays as columns into a 2-D array.
ma.concatenateopen in new window(arrays[, axis])Concatenate a sequence of arrays along the given axis.
ma.dstackopen in new window(*args, **kwargs)Stack arrays in sequence depth wise (along third axis).
ma.hstackopen in new window(*args, **kwargs)Stack arrays in sequence horizontally (column wise).
ma.hsplitopen in new window(*args, **kwargs)Split an array into multiple sub-arrays horizontally (column-wise).
ma.mr_open in new windowTranslate slice objects to concatenation along the first axis.
ma.row_stackopen in new window(*args, **kwargs)Stack arrays in sequence vertically (row wise).
ma.vstackopen in new window(*args, **kwargs)Stack arrays in sequence vertically (row wise).

Joining arrays

methoddescription
ma.stackopen in new window(*args, **kwargs)Join a sequence of arrays along a new axis.
ma.column_stackopen in new window(*args, **kwargs)Stack 1-D arrays as columns into a 2-D array.
ma.concatenateopen in new window(arrays[, axis])Concatenate a sequence of arrays along the given axis.
ma.appendopen in new window(a, b[, axis])Append values to the end of an array.
ma.dstackopen in new window(*args, **kwargs)Stack arrays in sequence depth wise (along third axis).
ma.hstackopen in new window(*args, **kwargs)Stack arrays in sequence horizontally (column wise).
ma.vstackopen in new window(*args, **kwargs)Stack arrays in sequence vertically (row wise).

Operations on masks

Creating a mask

methoddescription
ma.make_maskopen in new window(m[, copy, shrink, dtype])Create a boolean mask from an array.
ma.make_mask_noneopen in new window(newshape[, dtype])Return a boolean mask of the given shape, filled with False.
ma.mask_oropen in new window(m1, m2[, copy, shrink])Combine two masks with the logical_or operator.
ma.make_mask_descropen in new window(ndtype)Construct a dtype description list from a given dtype.

Accessing a mask

methoddescription
ma.getmaskopen in new window(a)Return the mask of a masked array, or nomask.
ma.getmaskarrayopen in new window(arr)Return the mask of a masked array, or full boolean array of False.
ma.masked_array.maskopen in new windowCurrent mask.

Finding masked data

methoddescription
ma.flatnotmasked_contiguousopen in new window(a)Find contiguous unmasked data in a masked array along the given axis.
ma.flatnotmasked_edgesopen in new window(a)Find the indices of the first and last unmasked values.
ma.notmasked_contiguousopen in new window(a[, axis])Find contiguous unmasked data in a masked array along the given axis.
ma.notmasked_edgesopen in new window(a[, axis])Find the indices of the first and last unmasked values along an axis.
ma.clump_maskedopen in new window(a)Returns a list of slices corresponding to the masked clumps of a 1-D array.
ma.clump_unmaskedopen in new window(a)Return list of slices corresponding to the unmasked clumps of a 1-D array.

Modifying a mask

methoddescription
ma.mask_colsopen in new window(a[, axis])Mask columns of a 2D array that contain masked values.
ma.mask_oropen in new window(m1, m2[, copy, shrink])Combine two masks with the logical_or operator.
ma.mask_rowcolsopen in new window(a[, axis])Mask rows and/or columns of a 2D array that contain masked values.
ma.mask_rowsopen in new window(a[, axis])Mask rows of a 2D array that contain masked values.
ma.harden_maskopen in new window(self)Force the mask to hard.
ma.soften_maskopen in new window(self)Force the mask to soft.
ma.MaskedArray.harden_maskopen in new window(self)Force the mask to hard.
ma.MaskedArray.soften_maskopen in new window(self)Force the mask to soft.
ma.MaskedArray.shrink_maskopen in new window(self)Reduce a mask to nomask when possible.
ma.MaskedArray.unshare_maskopen in new window(self)Copy the mask and set the sharedmask flag to False.

Conversion operations

> to a masked array

methoddescription
ma.asarrayopen in new window(a[, dtype, order])Convert the input to a masked array of the given data-type.
ma.asanyarrayopen in new window(a[, dtype])Convert the input to a masked array, conserving subclasses.
ma.fix_invalidopen in new window(a[, mask, copy, fill_value])Return input with invalid data masked and replaced by a fill value.
ma.masked_equalopen in new window(x, value[, copy])Mask an array where equal to a given value.
ma.masked_greateropen in new window(x, value[, copy])Mask an array where greater than a given value.
ma.masked_greater_equalopen in new window(x, value[, copy])Mask an array where greater than or equal to a given value.
ma.masked_insideopen in new window(x, v1, v2[, copy])Mask an array inside a given interval.
ma.masked_invalidopen in new window(a[, copy])Mask an array where invalid values occur (NaNs or infs).
ma.masked_lessopen in new window(x, value[, copy])Mask an array where less than a given value.
ma.masked_less_equalopen in new window(x, value[, copy])Mask an array where less than or equal to a given value.
ma.masked_not_equalopen in new window(x, value[, copy])Mask an array where not equal to a given value.
ma.masked_objectopen in new window(x, value[, copy, shrink])Mask the array x where the data are exactly equal to value.
ma.masked_outsideopen in new window(x, v1, v2[, copy])Mask an array outside a given interval.
ma.masked_valuesopen in new window(x, value[, rtol, atol, …])Mask using floating point equality.
ma.masked_whereopen in new window(condition, a[, copy])Mask an array where a condition is met.

> to a ndarray

methoddescription
ma.compress_colsopen in new window(a)Suppress whole columns of a 2-D array that contain masked values.
ma.compress_rowcolsopen in new window(x[, axis])Suppress the rows and/or columns of a 2-D array that contain masked values.
ma.compress_rowsopen in new window(a)Suppress whole rows of a 2-D array that contain masked values.
ma.compressedopen in new window(x)Return all the non-masked data as a 1-D array.
ma.filledopen in new window(a[, fill_value])Return input as an array with masked data replaced by a fill value.
ma.MaskedArray.compressedopen in new window(self)Return all the non-masked data as a 1-D array.
ma.MaskedArray.filledopen in new window(self[, fill_value])Return a copy of self, with masked values filled with a given value.

> to another object

methoddescription
ma.MaskedArray.tofileopen in new window(self, fid[, sep, format])Save a masked array to a file in binary format.
ma.MaskedArray.tolistopen in new window(self[, fill_value])Return the data portion of the masked array as a hierarchical Python list.
ma.MaskedArray.torecordsopen in new window(self)Transforms a masked array into a flexible-type array.
ma.MaskedArray.tobytesopen in new window(self[, fill_value, order])Return the array data as a string containing the raw bytes in the array.

Pickling and unpickling

methoddescription
ma.dumpopen in new window(a, F)Pickle a masked array to a file.
ma.dumpsopen in new window(a)Return a string corresponding to the pickling of a masked array.
ma.loadopen in new window(F)Wrapper around cPickle.load which accepts either a file-like object or a filename.
ma.loadsopen in new window(strg)Load a pickle from the current string.

Filling a masked array

methoddescription
ma.common_fill_valueopen in new window(a, b)Return the common filling value of two masked arrays, if any.
ma.default_fill_valueopen in new window(obj)Return the default fill value for the argument object.
ma.maximum_fill_valueopen in new window(obj)Return the minimum value that can be represented by the dtype of an object.
ma.maximum_fill_valueopen in new window(obj)Return the minimum value that can be represented by the dtype of an object.
ma.set_fill_valueopen in new window(a, fill_value)Set the filling value of a, if a is a masked array.
ma.MaskedArray.get_fill_valueopen in new window(self)The filling value of the masked array is a scalar.
ma.MaskedArray.set_fill_valueopen in new window(self[, value])
methoddescription
ma.MaskedArray.fill_valueThe filling value of the masked array is a scalar.

Masked arrays arithmetics

Arithmetics

methoddescription
ma.anomopen in new window(self[, axis, dtype])Compute the anomalies (deviations from the arithmetic mean) along the given axis.
ma.anomaliesopen in new window(self[, axis, dtype])Compute the anomalies (deviations from the arithmetic mean) along the given axis.
ma.averageopen in new window(a[, axis, weights, returned])Return the weighted average of array over the given axis.
ma.conjugateopen in new window(x, /[, out, where, casting, …])Return the complex conjugate, element-wise.
ma.corrcoefopen in new window(x[, y, rowvar, bias, …])Return Pearson product-moment correlation coefficients.
ma.covopen in new window(x[, y, rowvar, bias, allow_masked, ddof])Estimate the covariance matrix.
ma.cumsumopen in new window(self[, axis, dtype, out])Return the cumulative sum of the array elements over the given axis.
ma.cumprodopen in new window(self[, axis, dtype, out])Return the cumulative product of the array elements over the given axis.
ma.meanopen in new window(self[, axis, dtype, out, keepdims])Returns the average of the array elements along given axis.
ma.medianopen in new window(a[, axis, out, overwrite_input, …])Compute the median along the specified axis.
ma.poweropen in new window(a, b[, third])Returns element-wise base array raised to power from second array.
ma.prodopen in new window(self[, axis, dtype, out, keepdims])Return the product of the array elements over the given axis.
ma.stdopen in new window(self[, axis, dtype, out, ddof, keepdims])Returns the standard deviation of the array elements along given axis.
ma.sumopen in new window(self[, axis, dtype, out, keepdims])Return the sum of the array elements over the given axis.
ma.varopen in new window(self[, axis, dtype, out, ddof, keepdims])Compute the variance along the specified axis.
ma.MaskedArray.anomopen in new window(self[, axis, dtype])Compute the anomalies (deviations from the arithmetic mean) along the given axis.
ma.MaskedArray.cumprodopen in new window(self[, axis, dtype, out])Return the cumulative product of the array elements over the given axis.
ma.MaskedArray.cumsumopen in new window(self[, axis, dtype, out])Return the cumulative sum of the array elements over the given axis.
ma.MaskedArray.meanopen in new window(self[, axis, dtype, …])Returns the average of the array elements along given axis.
ma.MaskedArray.prodopen in new window(self[, axis, dtype, …])Return the product of the array elements over the given axis.
ma.MaskedArray.stdopen in new window(self[, axis, dtype, out, …])Returns the standard deviation of the array elements along given axis.
ma.MaskedArray.sumopen in new window(self[, axis, dtype, out, …])Return the sum of the array elements over the given axis.
ma.MaskedArray.varopen in new window(self[, axis, dtype, out, …])Compute the variance along the specified axis.

Minimum/maximum

methoddescription
ma.argmaxopen in new window(self[, axis, fill_value, out])Returns array of indices of the maximum values along the given axis.
ma.argminopen in new window(self[, axis, fill_value, out])Return array of indices to the minimum values along the given axis.
ma.maxopen in new window(obj[, axis, out, fill_value, keepdims])Return the maximum along a given axis.
ma.minopen in new window(obj[, axis, out, fill_value, keepdims])Return the minimum along a given axis.
ma.ptpopen in new window(obj[, axis, out, fill_value, keepdims])Return (maximum - minimum) along the given dimension (i.e.
ma.MaskedArray.argmaxopen in new window(self[, axis, …])Returns array of indices of the maximum values along the given axis.
ma.MaskedArray.argminopen in new window(self[, axis, …])Return array of indices to the minimum values along the given axis.
ma.MaskedArray.maxopen in new window(self[, axis, out, …])Return the maximum along a given axis.
ma.MaskedArray.minopen in new window(self[, axis, out, …])Return the minimum along a given axis.
ma.MaskedArray.ptpopen in new window(self[, axis, out, …])Return (maximum - minimum) along the given dimension (i.e.

Sorting

methoddescription
ma.argsortopen in new window(a[, axis, kind, order, endwith, …])Return an ndarray of indices that sort the array along the specified axis.
ma.sortopen in new window(a[, axis, kind, order, endwith, …])Sort the array, in-place
ma.MaskedArray.argsortopen in new window(self[, axis, kind, …])Return an ndarray of indices that sort the array along the specified axis.
ma.MaskedArray.sortopen in new window(self[, axis, kind, …])Sort the array, in-place

Algebra

methoddescription
ma.diagopen in new window(v[, k])Extract a diagonal or construct a diagonal array.
ma.dotopen in new window(a, b[, strict, out])Return the dot product of two arrays.
ma.identityopen in new window(n[, dtype])Return the identity array.
ma.inneropen in new window(a, b)Inner product of two arrays.
ma.innerproductopen in new window(a, b)Inner product of two arrays.
ma.outeropen in new window(a, b)Compute the outer product of two vectors.
ma.outerproductopen in new window(a, b)Compute the outer product of two vectors.
ma.traceopen in new window(self[, offset, axis1, axis2, …])Return the sum along diagonals of the array.
ma.transposeopen in new window(a[, axes])Permute the dimensions of an array.
ma.MaskedArray.traceopen in new window([offset, axis1, axis2, …])Return the sum along diagonals of the array.
ma.MaskedArray.transposeopen in new window(*axes)Returns a view of the array with axes transposed.

Polynomial fit

methoddescription
ma.vanderopen in new window(x[, n])Generate a Vandermonde matrix.
ma.polyfitopen in new window(x, y, deg[, rcond, full, w, cov])Least squares polynomial fit.

Clipping and rounding

methoddescription
ma.aroundopen in new window(a, *args, **kwargs)Round an array to the given number of decimals.
ma.clipopen in new window(a, a_min, a_max[, out])Clip (limit) the values in an array.
ma.roundopen in new window(a[, decimals, out])Return a copy of a, rounded to ‘decimals’ places.
ma.MaskedArray.clipopen in new window([min, max, out])Return an array whose values are limited to [min, max].
ma.MaskedArray.roundopen in new window(self[, decimals, out])Return each element rounded to the given number of decimals.

Miscellanea

methoddescription
ma.allequalopen in new window(a, b[, fill_value])Return True if all entries of a and b are equal, using fill_value as a truth value where either or both are masked.
ma.allcloseopen in new window(a, b[, masked_equal, rtol, atol])Returns True if two arrays are element-wise equal within a tolerance.
ma.apply_along_axisopen in new window(func1d, axis, arr, …)Apply a function to 1-D slices along the given axis.
ma.arangeopen in new window([start,] stop[, step,][, dtype])Return evenly spaced values within a given interval.
ma.chooseopen in new window(indices, choices[, out, mode])Use an index array to construct a new array from a set of choices.
ma.ediff1dopen in new window(arr[, to_end, to_begin])Compute the differences between consecutive elements of an array.
ma.indicesopen in new window(dimensions[, dtype, sparse])Return an array representing the indices of a grid.
ma.whereopen in new window(condition[, x, y])Return a masked array with elements from x or y, depending on condition.