doc_content
stringlengths 1
386k
| doc_id
stringlengths 5
188
|
---|---|
numpy.ma.dstack ma.dstack(*args, **kwargs) = <numpy.ma.extras._fromnxfunction_seq object>
Stack arrays in sequence depth wise (along third axis). This is equivalent to concatenation along the third axis after 2-D arrays of shape (M,N) have been reshaped to (M,N,1) and 1-D arrays of shape (N,) have been reshaped to (1,N,1). Rebuilds arrays divided by dsplit. This function makes most sense for arrays with up to 3 dimensions. For instance, for pixel-data with a height (first axis), width (second axis), and r/g/b channels (third axis). The functions concatenate, stack and block provide more general stacking and concatenation operations. Parameters
tupsequence of arrays
The arrays must have the same shape along all but the third axis. 1-D or 2-D arrays must have the same shape. Returns
stackedndarray
The array formed by stacking the given arrays, will be at least 3-D. See also concatenate
Join a sequence of arrays along an existing axis. stack
Join a sequence of arrays along a new axis. block
Assemble an nd-array from nested lists of blocks. vstack
Stack arrays in sequence vertically (row wise). hstack
Stack arrays in sequence horizontally (column wise). column_stack
Stack 1-D arrays as columns into a 2-D array. dsplit
Split array along third axis. Notes The function is applied to both the _data and the _mask, if any. Examples >>> a = np.array((1,2,3))
>>> b = np.array((2,3,4))
>>> np.dstack((a,b))
array([[[1, 2],
[2, 3],
[3, 4]]])
>>> a = np.array([[1],[2],[3]])
>>> b = np.array([[2],[3],[4]])
>>> np.dstack((a,b))
array([[[1, 2]],
[[2, 3]],
[[3, 4]]]) | numpy.reference.generated.numpy.ma.dstack |
numpy.ma.ediff1d ma.ediff1d(arr, to_end=None, to_begin=None)[source]
Compute the differences between consecutive elements of an array. This function is the equivalent of numpy.ediff1d that takes masked values into account, see numpy.ediff1d for details. See also numpy.ediff1d
Equivalent function for ndarrays. | numpy.reference.generated.numpy.ma.ediff1d |
numpy.ma.empty ma.empty(shape, dtype=float, order='C', *, like=None) = <numpy.ma.core._convert2ma object>
Return a new array of given shape and type, without initializing entries. Parameters
shapeint or tuple of int
Shape of the empty array, e.g., (2, 3) or 2.
dtypedata-type, optional
Desired output data-type for the array, e.g, numpy.int8. Default is numpy.float64.
order{‘C’, ‘F’}, optional, default: ‘C’
Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory.
likearray_like
Reference object to allow the creation of arrays which are not NumPy arrays. If an array-like passed in as like supports the __array_function__ protocol, the result will be defined by it. In this case, it ensures the creation of an array object compatible with that passed in via this argument. New in version 1.20.0. Returns
outMaskedArray
Array of uninitialized (arbitrary) data of the given shape, dtype, and order. Object arrays will be initialized to None. See also empty_like
Return an empty array with shape and type of input. ones
Return a new array setting values to one. zeros
Return a new array setting values to zero. full
Return a new array of given shape filled with value. Notes empty, unlike zeros, does not set the array values to zero, and may therefore be marginally faster. On the other hand, it requires the user to manually set all the values in the array, and should be used with caution. Examples >>> np.empty([2, 2])
array([[ -9.74499359e+001, 6.69583040e-309],
[ 2.13182611e-314, 3.06959433e-309]]) #uninitialized
>>> np.empty([2, 2], dtype=int)
array([[-1073741821, -1067949133],
[ 496041986, 19249760]]) #uninitialized | numpy.reference.generated.numpy.ma.empty |
numpy.ma.empty_like ma.empty_like(prototype, dtype=None, order='K', subok=True, shape=None) = <numpy.ma.core._convert2ma object>
Return a new array with the same shape and type as a given array. Parameters
prototypearray_like
The shape and data-type of prototype define these same attributes of the returned array.
dtypedata-type, optional
Overrides the data type of the result. New in version 1.6.0.
order{‘C’, ‘F’, ‘A’, or ‘K’}, optional
Overrides the memory layout of the result. ‘C’ means C-order, ‘F’ means F-order, ‘A’ means ‘F’ if prototype is Fortran contiguous, ‘C’ otherwise. ‘K’ means match the layout of prototype as closely as possible. New in version 1.6.0.
subokbool, optional.
If True, then the newly created array will use the sub-class type of prototype, otherwise it will be a base-class array. Defaults to True.
shapeint or sequence of ints, optional.
Overrides the shape of the result. If order=’K’ and the number of dimensions is unchanged, will try to keep order, otherwise, order=’C’ is implied. New in version 1.17.0. Returns
outMaskedArray
Array of uninitialized (arbitrary) data with the same shape and type as prototype. See also ones_like
Return an array of ones with shape and type of input. zeros_like
Return an array of zeros with shape and type of input. full_like
Return a new array with shape of input filled with value. empty
Return a new uninitialized array. Notes This function does not initialize the returned array; to do that use zeros_like or ones_like instead. It may be marginally faster than the functions that do set the array values. Examples >>> a = ([1,2,3], [4,5,6]) # a is array-like
>>> np.empty_like(a)
array([[-1073741821, -1073741821, 3], # uninitialized
[ 0, 0, -1073741821]])
>>> a = np.array([[1., 2., 3.],[4.,5.,6.]])
>>> np.empty_like(a)
array([[ -2.00000715e+000, 1.48219694e-323, -2.00000572e+000], # uninitialized
[ 4.38791518e-305, -2.00000715e+000, 4.17269252e-309]]) | numpy.reference.generated.numpy.ma.empty_like |
numpy.ma.expand_dims ma.expand_dims(a, axis)[source]
Expand the shape of an array. Insert a new axis that will appear at the axis position in the expanded array shape. Parameters
aarray_like
Input array.
axisint or tuple of ints
Position in the expanded axes where the new axis (or axes) is placed. Deprecated since version 1.13.0: Passing an axis where axis > a.ndim will be treated as axis == a.ndim, and passing axis < -a.ndim - 1 will be treated as axis == 0. This behavior is deprecated. Changed in version 1.18.0: A tuple of axes is now supported. Out of range axes as described above are now forbidden and raise an AxisError. Returns
resultndarray
View of a with the number of dimensions increased. See also squeeze
The inverse operation, removing singleton dimensions reshape
Insert, remove, and combine dimensions, and resize existing ones
doc.indexing, atleast_1d, atleast_2d, atleast_3d
Examples >>> x = np.array([1, 2])
>>> x.shape
(2,)
The following is equivalent to x[np.newaxis, :] or x[np.newaxis]: >>> y = np.expand_dims(x, axis=0)
>>> y
array([[1, 2]])
>>> y.shape
(1, 2)
The following is equivalent to x[:, np.newaxis]: >>> y = np.expand_dims(x, axis=1)
>>> y
array([[1],
[2]])
>>> y.shape
(2, 1)
axis may also be a tuple: >>> y = np.expand_dims(x, axis=(0, 1))
>>> y
array([[[1, 2]]])
>>> y = np.expand_dims(x, axis=(2, 0))
>>> y
array([[[1],
[2]]])
Note that some examples may use None instead of np.newaxis. These are the same objects: >>> np.newaxis is None
True | numpy.reference.generated.numpy.ma.expand_dims |
numpy.ma.filled ma.filled(a, fill_value=None)[source]
Return input as an array with masked data replaced by a fill value. If a is not a MaskedArray, a itself is returned. If a is a MaskedArray and fill_value is None, fill_value is set to a.fill_value. Parameters
aMaskedArray or array_like
An input object.
fill_valuearray_like, optional.
Can be scalar or non-scalar. If non-scalar, the resulting filled array should be broadcastable over input array. Default is None. Returns
andarray
The filled array. See also compressed
Examples >>> x = np.ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0],
... [1, 0, 0],
... [0, 0, 0]])
>>> x.filled()
array([[999999, 1, 2],
[999999, 4, 5],
[ 6, 7, 8]])
>>> x.filled(fill_value=333)
array([[333, 1, 2],
[333, 4, 5],
[ 6, 7, 8]])
>>> x.filled(fill_value=np.arange(3))
array([[0, 1, 2],
[0, 4, 5],
[6, 7, 8]]) | numpy.reference.generated.numpy.ma.filled |
numpy.ma.fix_invalid ma.fix_invalid(a, mask=False, copy=True, fill_value=None)[source]
Return input with invalid data masked and replaced by a fill value. Invalid data means values of nan, inf, etc. Parameters
aarray_like
Input array, a (subclass of) ndarray.
masksequence, optional
Mask. Must be convertible to an array of booleans with the same shape as data. True indicates a masked (i.e. invalid) data.
copybool, optional
Whether to use a copy of a (True) or to fix a in place (False). Default is True.
fill_valuescalar, optional
Value used for fixing invalid data. Default is None, in which case the a.fill_value is used. Returns
bMaskedArray
The input array with invalid entries fixed. Notes A copy is performed by default. Examples >>> x = np.ma.array([1., -1, np.nan, np.inf], mask=[1] + [0]*3)
>>> x
masked_array(data=[--, -1.0, nan, inf],
mask=[ True, False, False, False],
fill_value=1e+20)
>>> np.ma.fix_invalid(x)
masked_array(data=[--, -1.0, --, --],
mask=[ True, False, True, True],
fill_value=1e+20)
>>> fixed = np.ma.fix_invalid(x)
>>> fixed.data
array([ 1.e+00, -1.e+00, 1.e+20, 1.e+20])
>>> x.data
array([ 1., -1., nan, inf]) | numpy.reference.generated.numpy.ma.fix_invalid |
numpy.ma.flatnotmasked_contiguous ma.flatnotmasked_contiguous(a)[source]
Find contiguous unmasked data in a masked array along the given axis. Parameters
anarray
The input array. Returns
slice_listlist
A sorted sequence of slice objects (start index, end index). Changed in version 1.15.0: Now returns an empty list instead of None for a fully masked array See also
flatnotmasked_edges, notmasked_contiguous, notmasked_edges
clump_masked, clump_unmasked
Notes Only accepts 2-D arrays at most. Examples >>> a = np.ma.arange(10)
>>> np.ma.flatnotmasked_contiguous(a)
[slice(0, 10, None)]
>>> mask = (a < 3) | (a > 8) | (a == 5)
>>> a[mask] = np.ma.masked
>>> np.array(a[~a.mask])
array([3, 4, 6, 7, 8])
>>> np.ma.flatnotmasked_contiguous(a)
[slice(3, 5, None), slice(6, 9, None)]
>>> a[:] = np.ma.masked
>>> np.ma.flatnotmasked_contiguous(a)
[] | numpy.reference.generated.numpy.ma.flatnotmasked_contiguous |
numpy.ma.flatnotmasked_edges ma.flatnotmasked_edges(a)[source]
Find the indices of the first and last unmasked values. Expects a 1-D MaskedArray, returns None if all values are masked. Parameters
aarray_like
Input 1-D MaskedArray Returns
edgesndarray or None
The indices of first and last non-masked value in the array. Returns None if all values are masked. See also
flatnotmasked_contiguous, notmasked_contiguous, notmasked_edges
clump_masked, clump_unmasked
Notes Only accepts 1-D arrays. Examples >>> a = np.ma.arange(10)
>>> np.ma.flatnotmasked_edges(a)
array([0, 9])
>>> mask = (a < 3) | (a > 8) | (a == 5)
>>> a[mask] = np.ma.masked
>>> np.array(a[~a.mask])
array([3, 4, 6, 7, 8])
>>> np.ma.flatnotmasked_edges(a)
array([3, 8])
>>> a[:] = np.ma.masked
>>> print(np.ma.flatnotmasked_edges(a))
None | numpy.reference.generated.numpy.ma.flatnotmasked_edges |
numpy.ma.frombuffer ma.frombuffer(buffer, dtype=float, count=- 1, offset=0, *, like=None) = <numpy.ma.core._convert2ma object>
Interpret a buffer as a 1-dimensional array. Parameters
bufferbuffer_like
An object that exposes the buffer interface.
dtypedata-type, optional
Data-type of the returned array; default: float.
countint, optional
Number of items to read. -1 means all data in the buffer.
offsetint, optional
Start reading the buffer from this offset (in bytes); default: 0.
likearray_like
Reference object to allow the creation of arrays which are not NumPy arrays. If an array-like passed in as like supports the __array_function__ protocol, the result will be defined by it. In this case, it ensures the creation of an array object compatible with that passed in via this argument. New in version 1.20.0. Returns
out: MaskedArray
Notes If the buffer has data that is not in machine byte-order, this should be specified as part of the data-type, e.g.: >>> dt = np.dtype(int)
>>> dt = dt.newbyteorder('>')
>>> np.frombuffer(buf, dtype=dt)
The data of the resulting array will not be byteswapped, but will be interpreted correctly. Examples >>> s = b'hello world'
>>> np.frombuffer(s, dtype='S1', count=5, offset=6)
array([b'w', b'o', b'r', b'l', b'd'], dtype='|S1')
>>> np.frombuffer(b'\x01\x02', dtype=np.uint8)
array([1, 2], dtype=uint8)
>>> np.frombuffer(b'\x01\x02\x03\x04\x05', dtype=np.uint8, count=3)
array([1, 2, 3], dtype=uint8) | numpy.reference.generated.numpy.ma.frombuffer |
numpy.ma.fromfunction ma.fromfunction(function, shape, **dtype) = <numpy.ma.core._convert2ma object>
Construct an array by executing a function over each coordinate. The resulting array therefore has a value fn(x, y, z) at coordinate (x, y, z). Parameters
functioncallable
The function is called with N parameters, where N is the rank of shape. Each parameter represents the coordinates of the array varying along a specific axis. For example, if shape were (2, 2), then the parameters would be array([[0, 0], [1, 1]]) and array([[0, 1], [0, 1]])
shape(N,) tuple of ints
Shape of the output array, which also determines the shape of the coordinate arrays passed to function.
dtypedata-type, optional
Data-type of the coordinate arrays passed to function. By default, dtype is float.
likearray_like
Reference object to allow the creation of arrays which are not NumPy arrays. If an array-like passed in as like supports the __array_function__ protocol, the result will be defined by it. In this case, it ensures the creation of an array object compatible with that passed in via this argument. New in version 1.20.0. Returns
fromfunction: MaskedArray
The result of the call to function is passed back directly. Therefore the shape of fromfunction is completely determined by function. If function returns a scalar value, the shape of fromfunction would not match the shape parameter. See also
indices, meshgrid
Notes Keywords other than dtype are passed to function. Examples >>> np.fromfunction(lambda i, j: i == j, (3, 3), dtype=int)
array([[ True, False, False],
[False, True, False],
[False, False, True]])
>>> np.fromfunction(lambda i, j: i + j, (3, 3), dtype=int)
array([[0, 1, 2],
[1, 2, 3],
[2, 3, 4]]) | numpy.reference.generated.numpy.ma.fromfunction |
numpy.ma.getdata ma.getdata(a, subok=True)[source]
Return the data of a masked array as an ndarray. Return the data of a (if any) as an ndarray if a is a MaskedArray, else return a as a ndarray or subclass (depending on subok) if not. Parameters
aarray_like
Input MaskedArray, alternatively a ndarray or a subclass thereof.
subokbool
Whether to force the output to be a pure ndarray (False) or to return a subclass of ndarray if appropriate (True, default). See also getmask
Return the mask of a masked array, or nomask. getmaskarray
Return the mask of a masked array, or full array of False. Examples >>> import numpy.ma as ma
>>> a = ma.masked_equal([[1,2],[3,4]], 2)
>>> a
masked_array(
data=[[1, --],
[3, 4]],
mask=[[False, True],
[False, False]],
fill_value=2)
>>> ma.getdata(a)
array([[1, 2],
[3, 4]])
Equivalently use the MaskedArray data attribute. >>> a.data
array([[1, 2],
[3, 4]]) | numpy.reference.generated.numpy.ma.getdata |
numpy.ma.getmask ma.getmask(a)[source]
Return the mask of a masked array, or nomask. Return the mask of a as an ndarray if a is a MaskedArray and the mask is not nomask, else return nomask. To guarantee a full array of booleans of the same shape as a, use getmaskarray. Parameters
aarray_like
Input MaskedArray for which the mask is required. See also getdata
Return the data of a masked array as an ndarray. getmaskarray
Return the mask of a masked array, or full array of False. Examples >>> import numpy.ma as ma
>>> a = ma.masked_equal([[1,2],[3,4]], 2)
>>> a
masked_array(
data=[[1, --],
[3, 4]],
mask=[[False, True],
[False, False]],
fill_value=2)
>>> ma.getmask(a)
array([[False, True],
[False, False]])
Equivalently use the MaskedArray mask attribute. >>> a.mask
array([[False, True],
[False, False]])
Result when mask == nomask >>> b = ma.masked_array([[1,2],[3,4]])
>>> b
masked_array(
data=[[1, 2],
[3, 4]],
mask=False,
fill_value=999999)
>>> ma.nomask
False
>>> ma.getmask(b) == ma.nomask
True
>>> b.mask == ma.nomask
True | numpy.reference.generated.numpy.ma.getmask |
numpy.ma.getmaskarray ma.getmaskarray(arr)[source]
Return the mask of a masked array, or full boolean array of False. Return the mask of arr as an ndarray if arr is a MaskedArray and the mask is not nomask, else return a full boolean array of False of the same shape as arr. Parameters
arrarray_like
Input MaskedArray for which the mask is required. See also getmask
Return the mask of a masked array, or nomask. getdata
Return the data of a masked array as an ndarray. Examples >>> import numpy.ma as ma
>>> a = ma.masked_equal([[1,2],[3,4]], 2)
>>> a
masked_array(
data=[[1, --],
[3, 4]],
mask=[[False, True],
[False, False]],
fill_value=2)
>>> ma.getmaskarray(a)
array([[False, True],
[False, False]])
Result when mask == nomask >>> b = ma.masked_array([[1,2],[3,4]])
>>> b
masked_array(
data=[[1, 2],
[3, 4]],
mask=False,
fill_value=999999)
>>> ma.getmaskarray(b)
array([[False, False],
[False, False]]) | numpy.reference.generated.numpy.ma.getmaskarray |
numpy.ma.harden_mask ma.harden_mask(self) = <numpy.ma.core._frommethod object>
Force the mask to hard. Whether the mask of a masked array is hard or soft is determined by its hardmask property. harden_mask sets hardmask to True. See also ma.MaskedArray.hardmask | numpy.reference.generated.numpy.ma.harden_mask |
numpy.ma.hsplit ma.hsplit(*args, **kwargs) = <numpy.ma.extras._fromnxfunction_single object>
Split an array into multiple sub-arrays horizontally (column-wise). Please refer to the split documentation. hsplit is equivalent to split with axis=1, the array is always split along the second axis regardless of the array dimension. See also split
Split an array into multiple sub-arrays of equal size. Notes The function is applied to both the _data and the _mask, if any. Examples >>> x = np.arange(16.0).reshape(4, 4)
>>> x
array([[ 0., 1., 2., 3.],
[ 4., 5., 6., 7.],
[ 8., 9., 10., 11.],
[12., 13., 14., 15.]])
>>> np.hsplit(x, 2)
[array([[ 0., 1.],
[ 4., 5.],
[ 8., 9.],
[12., 13.]]),
array([[ 2., 3.],
[ 6., 7.],
[10., 11.],
[14., 15.]])]
>>> np.hsplit(x, np.array([3, 6]))
[array([[ 0., 1., 2.],
[ 4., 5., 6.],
[ 8., 9., 10.],
[12., 13., 14.]]),
array([[ 3.],
[ 7.],
[11.],
[15.]]),
array([], shape=(4, 0), dtype=float64)]
With a higher dimensional array the split is still along the second axis. >>> x = np.arange(8.0).reshape(2, 2, 2)
>>> x
array([[[0., 1.],
[2., 3.]],
[[4., 5.],
[6., 7.]]])
>>> np.hsplit(x, 2)
[array([[[0., 1.]],
[[4., 5.]]]),
array([[[2., 3.]],
[[6., 7.]]])] | numpy.reference.generated.numpy.ma.hsplit |
numpy.ma.hstack ma.hstack(*args, **kwargs) = <numpy.ma.extras._fromnxfunction_seq object>
Stack arrays in sequence horizontally (column wise). This is equivalent to concatenation along the second axis, except for 1-D arrays where it concatenates along the first axis. Rebuilds arrays divided by hsplit. This function makes most sense for arrays with up to 3 dimensions. For instance, for pixel-data with a height (first axis), width (second axis), and r/g/b channels (third axis). The functions concatenate, stack and block provide more general stacking and concatenation operations. Parameters
tupsequence of ndarrays
The arrays must have the same shape along all but the second axis, except 1-D arrays which can be any length. Returns
stackedndarray
The array formed by stacking the given arrays. See also concatenate
Join a sequence of arrays along an existing axis. stack
Join a sequence of arrays along a new axis. block
Assemble an nd-array from nested lists of blocks. vstack
Stack arrays in sequence vertically (row wise). dstack
Stack arrays in sequence depth wise (along third axis). column_stack
Stack 1-D arrays as columns into a 2-D array. hsplit
Split an array into multiple sub-arrays horizontally (column-wise). Notes The function is applied to both the _data and the _mask, if any. Examples >>> a = np.array((1,2,3))
>>> b = np.array((4,5,6))
>>> np.hstack((a,b))
array([1, 2, 3, 4, 5, 6])
>>> a = np.array([[1],[2],[3]])
>>> b = np.array([[4],[5],[6]])
>>> np.hstack((a,b))
array([[1, 4],
[2, 5],
[3, 6]]) | numpy.reference.generated.numpy.ma.hstack |
numpy.ma.identity ma.identity(n, dtype=None) = <numpy.ma.core._convert2ma object>
Return the identity array. The identity array is a square array with ones on the main diagonal. Parameters
nint
Number of rows (and columns) in n x n output.
dtypedata-type, optional
Data-type of the output. Defaults to float.
likearray_like
Reference object to allow the creation of arrays which are not NumPy arrays. If an array-like passed in as like supports the __array_function__ protocol, the result will be defined by it. In this case, it ensures the creation of an array object compatible with that passed in via this argument. New in version 1.20.0. Returns
outMaskedArray
n x n array with its main diagonal set to one, and all other elements 0. Examples >>> np.identity(3)
array([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]]) | numpy.reference.generated.numpy.ma.identity |
numpy.ma.indices ma.indices(dimensions, dtype=<class 'int'>, sparse=False) = <numpy.ma.core._convert2ma object>
Return an array representing the indices of a grid. Compute an array where the subarrays contain index values 0, 1, … varying only along the corresponding axis. Parameters
dimensionssequence of ints
The shape of the grid.
dtypedtype, optional
Data type of the result.
sparseboolean, optional
Return a sparse representation of the grid instead of a dense representation. Default is False. New in version 1.17. Returns
gridone MaskedArray or tuple of MaskedArrays
If sparse is False:
Returns one array of grid indices, grid.shape = (len(dimensions),) + tuple(dimensions). If sparse is True:
Returns a tuple of arrays, with grid[i].shape = (1, ..., 1, dimensions[i], 1, ..., 1) with dimensions[i] in the ith place See also
mgrid, ogrid, meshgrid
Notes The output shape in the dense case is obtained by prepending the number of dimensions in front of the tuple of dimensions, i.e. if dimensions is a tuple (r0, ..., rN-1) of length N, the output shape is (N, r0, ..., rN-1). The subarrays grid[k] contains the N-D array of indices along the k-th axis. Explicitly: grid[k, i0, i1, ..., iN-1] = ik
Examples >>> grid = np.indices((2, 3))
>>> grid.shape
(2, 2, 3)
>>> grid[0] # row indices
array([[0, 0, 0],
[1, 1, 1]])
>>> grid[1] # column indices
array([[0, 1, 2],
[0, 1, 2]])
The indices can be used as an index into an array. >>> x = np.arange(20).reshape(5, 4)
>>> row, col = np.indices((2, 3))
>>> x[row, col]
array([[0, 1, 2],
[4, 5, 6]])
Note that it would be more straightforward in the above example to extract the required elements directly with x[:2, :3]. If sparse is set to true, the grid will be returned in a sparse representation. >>> i, j = np.indices((2, 3), sparse=True)
>>> i.shape
(2, 1)
>>> j.shape
(1, 3)
>>> i # row indices
array([[0],
[1]])
>>> j # column indices
array([[0, 1, 2]]) | numpy.reference.generated.numpy.ma.indices |
numpy.ma.inner ma.inner(a, b, /)[source]
Inner product of two arrays. Ordinary inner product of vectors for 1-D arrays (without complex conjugation), in higher dimensions a sum product over the last axes. Parameters
a, barray_like
If a and b are nonscalar, their last dimensions must match. Returns
outndarray
If a and b are both scalars or both 1-D arrays then a scalar is returned; otherwise an array is returned. out.shape = (*a.shape[:-1], *b.shape[:-1]) Raises
ValueError
If both a and b are nonscalar and their last dimensions have different sizes. See also tensordot
Sum products over arbitrary axes. dot
Generalised matrix product, using second last dimension of b. einsum
Einstein summation convention. Notes Masked values are replaced by 0. For vectors (1-D arrays) it computes the ordinary inner-product: np.inner(a, b) = sum(a[:]*b[:])
More generally, if ndim(a) = r > 0 and ndim(b) = s > 0: np.inner(a, b) = np.tensordot(a, b, axes=(-1,-1))
or explicitly: np.inner(a, b)[i0,...,ir-2,j0,...,js-2]
= sum(a[i0,...,ir-2,:]*b[j0,...,js-2,:])
In addition a or b may be scalars, in which case: np.inner(a,b) = a*b
Examples Ordinary inner product for vectors: >>> a = np.array([1,2,3])
>>> b = np.array([0,1,0])
>>> np.inner(a, b)
2
Some multidimensional examples: >>> a = np.arange(24).reshape((2,3,4))
>>> b = np.arange(4)
>>> c = np.inner(a, b)
>>> c.shape
(2, 3)
>>> c
array([[ 14, 38, 62],
[ 86, 110, 134]])
>>> a = np.arange(2).reshape((1,1,2))
>>> b = np.arange(6).reshape((3,2))
>>> c = np.inner(a, b)
>>> c.shape
(1, 1, 3)
>>> c
array([[[1, 3, 5]]])
An example where b is a scalar: >>> np.inner(np.eye(2), 7)
array([[7., 0.],
[0., 7.]]) | numpy.reference.generated.numpy.ma.inner |
numpy.ma.innerproduct ma.innerproduct(a, b, /)[source]
Inner product of two arrays. Ordinary inner product of vectors for 1-D arrays (without complex conjugation), in higher dimensions a sum product over the last axes. Parameters
a, barray_like
If a and b are nonscalar, their last dimensions must match. Returns
outndarray
If a and b are both scalars or both 1-D arrays then a scalar is returned; otherwise an array is returned. out.shape = (*a.shape[:-1], *b.shape[:-1]) Raises
ValueError
If both a and b are nonscalar and their last dimensions have different sizes. See also tensordot
Sum products over arbitrary axes. dot
Generalised matrix product, using second last dimension of b. einsum
Einstein summation convention. Notes Masked values are replaced by 0. For vectors (1-D arrays) it computes the ordinary inner-product: np.inner(a, b) = sum(a[:]*b[:])
More generally, if ndim(a) = r > 0 and ndim(b) = s > 0: np.inner(a, b) = np.tensordot(a, b, axes=(-1,-1))
or explicitly: np.inner(a, b)[i0,...,ir-2,j0,...,js-2]
= sum(a[i0,...,ir-2,:]*b[j0,...,js-2,:])
In addition a or b may be scalars, in which case: np.inner(a,b) = a*b
Examples Ordinary inner product for vectors: >>> a = np.array([1,2,3])
>>> b = np.array([0,1,0])
>>> np.inner(a, b)
2
Some multidimensional examples: >>> a = np.arange(24).reshape((2,3,4))
>>> b = np.arange(4)
>>> c = np.inner(a, b)
>>> c.shape
(2, 3)
>>> c
array([[ 14, 38, 62],
[ 86, 110, 134]])
>>> a = np.arange(2).reshape((1,1,2))
>>> b = np.arange(6).reshape((3,2))
>>> c = np.inner(a, b)
>>> c.shape
(1, 1, 3)
>>> c
array([[[1, 3, 5]]])
An example where b is a scalar: >>> np.inner(np.eye(2), 7)
array([[7., 0.],
[0., 7.]]) | numpy.reference.generated.numpy.ma.innerproduct |
numpy.ma.is_mask ma.is_mask(m)[source]
Return True if m is a valid, standard mask. This function does not check the contents of the input, only that the type is MaskType. In particular, this function returns False if the mask has a flexible dtype. Parameters
marray_like
Array to test. Returns
resultbool
True if m.dtype.type is MaskType, False otherwise. See also ma.isMaskedArray
Test whether input is an instance of MaskedArray. Examples >>> import numpy.ma as ma
>>> m = ma.masked_equal([0, 1, 0, 2, 3], 0)
>>> m
masked_array(data=[--, 1, --, 2, 3],
mask=[ True, False, True, False, False],
fill_value=0)
>>> ma.is_mask(m)
False
>>> ma.is_mask(m.mask)
True
Input must be an ndarray (or have similar attributes) for it to be considered a valid mask. >>> m = [False, True, False]
>>> ma.is_mask(m)
False
>>> m = np.array([False, True, False])
>>> m
array([False, True, False])
>>> ma.is_mask(m)
True
Arrays with complex dtypes don’t return True. >>> dtype = np.dtype({'names':['monty', 'pithon'],
... 'formats':[bool, bool]})
>>> dtype
dtype([('monty', '|b1'), ('pithon', '|b1')])
>>> m = np.array([(True, False), (False, True), (True, False)],
... dtype=dtype)
>>> m
array([( True, False), (False, True), ( True, False)],
dtype=[('monty', '?'), ('pithon', '?')])
>>> ma.is_mask(m)
False | numpy.reference.generated.numpy.ma.is_mask |
numpy.ma.is_masked ma.is_masked(x)[source]
Determine whether input has masked values. Accepts any object as input, but always returns False unless the input is a MaskedArray containing masked values. Parameters
xarray_like
Array to check for masked values. Returns
resultbool
True if x is a MaskedArray with masked values, False otherwise. Examples >>> import numpy.ma as ma
>>> x = ma.masked_equal([0, 1, 0, 2, 3], 0)
>>> x
masked_array(data=[--, 1, --, 2, 3],
mask=[ True, False, True, False, False],
fill_value=0)
>>> ma.is_masked(x)
True
>>> x = ma.masked_equal([0, 1, 0, 2, 3], 42)
>>> x
masked_array(data=[0, 1, 0, 2, 3],
mask=False,
fill_value=42)
>>> ma.is_masked(x)
False
Always returns False if x isn’t a MaskedArray. >>> x = [False, True, False]
>>> ma.is_masked(x)
False
>>> x = 'a string'
>>> ma.is_masked(x)
False | numpy.reference.generated.numpy.ma.is_masked |
numpy.ma.isarray ma.isarray(x)[source]
Test whether input is an instance of MaskedArray. This function returns True if x is an instance of MaskedArray and returns False otherwise. Any object is accepted as input. Parameters
xobject
Object to test. Returns
resultbool
True if x is a MaskedArray. See also isMA
Alias to isMaskedArray. isarray
Alias to isMaskedArray. Examples >>> import numpy.ma as ma
>>> a = np.eye(3, 3)
>>> a
array([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 0., 0., 1.]])
>>> m = ma.masked_values(a, 0)
>>> m
masked_array(
data=[[1.0, --, --],
[--, 1.0, --],
[--, --, 1.0]],
mask=[[False, True, True],
[ True, False, True],
[ True, True, False]],
fill_value=0.0)
>>> ma.isMaskedArray(a)
False
>>> ma.isMaskedArray(m)
True
>>> ma.isMaskedArray([0, 1, 2])
False | numpy.reference.generated.numpy.ma.isarray |
numpy.ma.isMA ma.isMA(x)[source]
Test whether input is an instance of MaskedArray. This function returns True if x is an instance of MaskedArray and returns False otherwise. Any object is accepted as input. Parameters
xobject
Object to test. Returns
resultbool
True if x is a MaskedArray. See also isMA
Alias to isMaskedArray. isarray
Alias to isMaskedArray. Examples >>> import numpy.ma as ma
>>> a = np.eye(3, 3)
>>> a
array([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 0., 0., 1.]])
>>> m = ma.masked_values(a, 0)
>>> m
masked_array(
data=[[1.0, --, --],
[--, 1.0, --],
[--, --, 1.0]],
mask=[[False, True, True],
[ True, False, True],
[ True, True, False]],
fill_value=0.0)
>>> ma.isMaskedArray(a)
False
>>> ma.isMaskedArray(m)
True
>>> ma.isMaskedArray([0, 1, 2])
False | numpy.reference.generated.numpy.ma.isma |
numpy.ma.isMaskedArray ma.isMaskedArray(x)[source]
Test whether input is an instance of MaskedArray. This function returns True if x is an instance of MaskedArray and returns False otherwise. Any object is accepted as input. Parameters
xobject
Object to test. Returns
resultbool
True if x is a MaskedArray. See also isMA
Alias to isMaskedArray. isarray
Alias to isMaskedArray. Examples >>> import numpy.ma as ma
>>> a = np.eye(3, 3)
>>> a
array([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 0., 0., 1.]])
>>> m = ma.masked_values(a, 0)
>>> m
masked_array(
data=[[1.0, --, --],
[--, 1.0, --],
[--, --, 1.0]],
mask=[[False, True, True],
[ True, False, True],
[ True, True, False]],
fill_value=0.0)
>>> ma.isMaskedArray(a)
False
>>> ma.isMaskedArray(m)
True
>>> ma.isMaskedArray([0, 1, 2])
False | numpy.reference.generated.numpy.ma.ismaskedarray |
numpy.ma.make_mask ma.make_mask(m, copy=False, shrink=True, dtype=<class 'numpy.bool_'>)[source]
Create a boolean mask from an array. Return m as a boolean mask, creating a copy if necessary or requested. The function can accept any sequence that is convertible to integers, or nomask. Does not require that contents must be 0s and 1s, values of 0 are interpreted as False, everything else as True. Parameters
marray_like
Potential mask.
copybool, optional
Whether to return a copy of m (True) or m itself (False).
shrinkbool, optional
Whether to shrink m to nomask if all its values are False.
dtypedtype, optional
Data-type of the output mask. By default, the output mask has a dtype of MaskType (bool). If the dtype is flexible, each field has a boolean dtype. This is ignored when m is nomask, in which case nomask is always returned. Returns
resultndarray
A boolean mask derived from m. Examples >>> import numpy.ma as ma
>>> m = [True, False, True, True]
>>> ma.make_mask(m)
array([ True, False, True, True])
>>> m = [1, 0, 1, 1]
>>> ma.make_mask(m)
array([ True, False, True, True])
>>> m = [1, 0, 2, -3]
>>> ma.make_mask(m)
array([ True, False, True, True])
Effect of the shrink parameter. >>> m = np.zeros(4)
>>> m
array([0., 0., 0., 0.])
>>> ma.make_mask(m)
False
>>> ma.make_mask(m, shrink=False)
array([False, False, False, False])
Using a flexible dtype. >>> m = [1, 0, 1, 1]
>>> n = [0, 1, 0, 0]
>>> arr = []
>>> for man, mouse in zip(m, n):
... arr.append((man, mouse))
>>> arr
[(1, 0), (0, 1), (1, 0), (1, 0)]
>>> dtype = np.dtype({'names':['man', 'mouse'],
... 'formats':[np.int64, np.int64]})
>>> arr = np.array(arr, dtype=dtype)
>>> arr
array([(1, 0), (0, 1), (1, 0), (1, 0)],
dtype=[('man', '<i8'), ('mouse', '<i8')])
>>> ma.make_mask(arr, dtype=dtype)
array([(True, False), (False, True), (True, False), (True, False)],
dtype=[('man', '|b1'), ('mouse', '|b1')]) | numpy.reference.generated.numpy.ma.make_mask |
numpy.ma.make_mask_descr ma.make_mask_descr(ndtype)[source]
Construct a dtype description list from a given dtype. Returns a new dtype object, with the type of all fields in ndtype to a boolean type. Field names are not altered. Parameters
ndtypedtype
The dtype to convert. Returns
resultdtype
A dtype that looks like ndtype, the type of all fields is boolean. Examples >>> import numpy.ma as ma
>>> dtype = np.dtype({'names':['foo', 'bar'],
... 'formats':[np.float32, np.int64]})
>>> dtype
dtype([('foo', '<f4'), ('bar', '<i8')])
>>> ma.make_mask_descr(dtype)
dtype([('foo', '|b1'), ('bar', '|b1')])
>>> ma.make_mask_descr(np.float32)
dtype('bool') | numpy.reference.generated.numpy.ma.make_mask_descr |
numpy.ma.make_mask_none ma.make_mask_none(newshape, dtype=None)[source]
Return a boolean mask of the given shape, filled with False. This function returns a boolean ndarray with all entries False, that can be used in common mask manipulations. If a complex dtype is specified, the type of each field is converted to a boolean type. Parameters
newshapetuple
A tuple indicating the shape of the mask.
dtype{None, dtype}, optional
If None, use a MaskType instance. Otherwise, use a new datatype with the same fields as dtype, converted to boolean types. Returns
resultndarray
An ndarray of appropriate shape and dtype, filled with False. See also make_mask
Create a boolean mask from an array. make_mask_descr
Construct a dtype description list from a given dtype. Examples >>> import numpy.ma as ma
>>> ma.make_mask_none((3,))
array([False, False, False])
Defining a more complex dtype. >>> dtype = np.dtype({'names':['foo', 'bar'],
... 'formats':[np.float32, np.int64]})
>>> dtype
dtype([('foo', '<f4'), ('bar', '<i8')])
>>> ma.make_mask_none((3,), dtype=dtype)
array([(False, False), (False, False), (False, False)],
dtype=[('foo', '|b1'), ('bar', '|b1')]) | numpy.reference.generated.numpy.ma.make_mask_none |
numpy.ma.mask_cols ma.mask_cols(a, axis=<no value>)[source]
Mask columns of a 2D array that contain masked values. This function is a shortcut to mask_rowcols with axis equal to 1. See also mask_rowcols
Mask rows and/or columns of a 2D array. masked_where
Mask where a condition is met. Examples >>> import numpy.ma as ma
>>> a = np.zeros((3, 3), dtype=int)
>>> a[1, 1] = 1
>>> a
array([[0, 0, 0],
[0, 1, 0],
[0, 0, 0]])
>>> a = ma.masked_equal(a, 1)
>>> a
masked_array(
data=[[0, 0, 0],
[0, --, 0],
[0, 0, 0]],
mask=[[False, False, False],
[False, True, False],
[False, False, False]],
fill_value=1)
>>> ma.mask_cols(a)
masked_array(
data=[[0, --, 0],
[0, --, 0],
[0, --, 0]],
mask=[[False, True, False],
[False, True, False],
[False, True, False]],
fill_value=1) | numpy.reference.generated.numpy.ma.mask_cols |
numpy.ma.mask_or ma.mask_or(m1, m2, copy=False, shrink=True)[source]
Combine two masks with the logical_or operator. The result may be a view on m1 or m2 if the other is nomask (i.e. False). Parameters
m1, m2array_like
Input masks.
copybool, optional
If copy is False and one of the inputs is nomask, return a view of the other input mask. Defaults to False.
shrinkbool, optional
Whether to shrink the output to nomask if all its values are False. Defaults to True. Returns
maskoutput mask
The result masks values that are masked in either m1 or m2. Raises
ValueError
If m1 and m2 have different flexible dtypes. Examples >>> m1 = np.ma.make_mask([0, 1, 1, 0])
>>> m2 = np.ma.make_mask([1, 0, 0, 0])
>>> np.ma.mask_or(m1, m2)
array([ True, True, True, False]) | numpy.reference.generated.numpy.ma.mask_or |
numpy.ma.mask_rowcols ma.mask_rowcols(a, axis=None)[source]
Mask rows and/or columns of a 2D array that contain masked values. Mask whole rows and/or columns of a 2D array that contain masked values. The masking behavior is selected using the axis parameter. If axis is None, rows and columns are masked. If axis is 0, only rows are masked. If axis is 1 or -1, only columns are masked. Parameters
aarray_like, MaskedArray
The array to mask. If not a MaskedArray instance (or if no array elements are masked). The result is a MaskedArray with mask set to nomask (False). Must be a 2D array.
axisint, optional
Axis along which to perform the operation. If None, applies to a flattened version of the array. Returns
aMaskedArray
A modified version of the input array, masked depending on the value of the axis parameter. Raises
NotImplementedError
If input array a is not 2D. See also mask_rows
Mask rows of a 2D array that contain masked values. mask_cols
Mask cols of a 2D array that contain masked values. masked_where
Mask where a condition is met. Notes The input array’s mask is modified by this function. Examples >>> import numpy.ma as ma
>>> a = np.zeros((3, 3), dtype=int)
>>> a[1, 1] = 1
>>> a
array([[0, 0, 0],
[0, 1, 0],
[0, 0, 0]])
>>> a = ma.masked_equal(a, 1)
>>> a
masked_array(
data=[[0, 0, 0],
[0, --, 0],
[0, 0, 0]],
mask=[[False, False, False],
[False, True, False],
[False, False, False]],
fill_value=1)
>>> ma.mask_rowcols(a)
masked_array(
data=[[0, --, 0],
[--, --, --],
[0, --, 0]],
mask=[[False, True, False],
[ True, True, True],
[False, True, False]],
fill_value=1) | numpy.reference.generated.numpy.ma.mask_rowcols |
numpy.ma.mask_rows ma.mask_rows(a, axis=<no value>)[source]
Mask rows of a 2D array that contain masked values. This function is a shortcut to mask_rowcols with axis equal to 0. See also mask_rowcols
Mask rows and/or columns of a 2D array. masked_where
Mask where a condition is met. Examples >>> import numpy.ma as ma
>>> a = np.zeros((3, 3), dtype=int)
>>> a[1, 1] = 1
>>> a
array([[0, 0, 0],
[0, 1, 0],
[0, 0, 0]])
>>> a = ma.masked_equal(a, 1)
>>> a
masked_array(
data=[[0, 0, 0],
[0, --, 0],
[0, 0, 0]],
mask=[[False, False, False],
[False, True, False],
[False, False, False]],
fill_value=1)
>>> ma.mask_rows(a)
masked_array(
data=[[0, 0, 0],
[--, --, --],
[0, 0, 0]],
mask=[[False, False, False],
[ True, True, True],
[False, False, False]],
fill_value=1) | numpy.reference.generated.numpy.ma.mask_rows |
numpy.ma.masked_all ma.masked_all(shape, dtype=<class 'float'>)[source]
Empty masked array with all elements masked. Return an empty masked array of the given shape and dtype, where all the data are masked. Parameters
shapetuple
Shape of the required MaskedArray.
dtypedtype, optional
Data type of the output. Returns
aMaskedArray
A masked array with all data masked. See also masked_all_like
Empty masked array modelled on an existing array. Examples >>> import numpy.ma as ma
>>> ma.masked_all((3, 3))
masked_array(
data=[[--, --, --],
[--, --, --],
[--, --, --]],
mask=[[ True, True, True],
[ True, True, True],
[ True, True, True]],
fill_value=1e+20,
dtype=float64)
The dtype parameter defines the underlying data type. >>> a = ma.masked_all((3, 3))
>>> a.dtype
dtype('float64')
>>> a = ma.masked_all((3, 3), dtype=np.int32)
>>> a.dtype
dtype('int32') | numpy.reference.generated.numpy.ma.masked_all |
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. Examples >>> import numpy.ma as ma
>>> arr = np.zeros((2, 3), dtype=np.float32)
>>> arr
array([[0., 0., 0.],
[0., 0., 0.]], dtype=float32)
>>> ma.masked_all_like(arr)
masked_array(
data=[[--, --, --],
[--, --, --]],
mask=[[ True, True, True],
[ True, True, True]],
fill_value=1e+20,
dtype=float32)
The dtype of the masked array matches the dtype of arr. >>> arr.dtype
dtype('float32')
>>> ma.masked_all_like(arr).dtype
dtype('float32') | numpy.reference.generated.numpy.ma.masked_all_like |
numpy.ma.masked_equal ma.masked_equal(x, value, copy=True)[source]
Mask an array where equal to a given value. This function is a shortcut to masked_where, with condition = (x == value). For floating point arrays, consider using masked_values(x, value). See also masked_where
Mask where a condition is met. masked_values
Mask using floating point equality. Examples >>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_equal(a, 2)
masked_array(data=[0, 1, --, 3],
mask=[False, False, True, False],
fill_value=2) | numpy.reference.generated.numpy.ma.masked_equal |
numpy.ma.masked_greater ma.masked_greater(x, value, copy=True)[source]
Mask an array where greater than a given value. This function is a shortcut to masked_where, with condition = (x > value). See also masked_where
Mask where a condition is met. Examples >>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_greater(a, 2)
masked_array(data=[0, 1, 2, --],
mask=[False, False, False, True],
fill_value=999999) | numpy.reference.generated.numpy.ma.masked_greater |
numpy.ma.masked_greater_equal ma.masked_greater_equal(x, value, copy=True)[source]
Mask an array where greater than or equal to a given value. This function is a shortcut to masked_where, with condition = (x >= value). See also masked_where
Mask where a condition is met. Examples >>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_greater_equal(a, 2)
masked_array(data=[0, 1, --, --],
mask=[False, False, True, True],
fill_value=999999) | numpy.reference.generated.numpy.ma.masked_greater_equal |
numpy.ma.masked_inside ma.masked_inside(x, v1, v2, copy=True)[source]
Mask an array inside a given interval. Shortcut to masked_where, where condition is True for x inside the interval [v1,v2] (v1 <= x <= v2). The boundaries v1 and v2 can be given in either order. See also masked_where
Mask where a condition is met. Notes The array x is prefilled with its filling value. Examples >>> import numpy.ma as ma
>>> x = [0.31, 1.2, 0.01, 0.2, -0.4, -1.1]
>>> ma.masked_inside(x, -0.3, 0.3)
masked_array(data=[0.31, 1.2, --, --, -0.4, -1.1],
mask=[False, False, True, True, False, False],
fill_value=1e+20)
The order of v1 and v2 doesn’t matter. >>> ma.masked_inside(x, 0.3, -0.3)
masked_array(data=[0.31, 1.2, --, --, -0.4, -1.1],
mask=[False, False, True, True, False, False],
fill_value=1e+20) | numpy.reference.generated.numpy.ma.masked_inside |
numpy.ma.masked_invalid ma.masked_invalid(a, copy=True)[source]
Mask an array where invalid values occur (NaNs or infs). This function is a shortcut to masked_where, with condition = ~(np.isfinite(a)). Any pre-existing mask is conserved. Only applies to arrays with a dtype where NaNs or infs make sense (i.e. floating point types), but accepts any array_like object. See also masked_where
Mask where a condition is met. Examples >>> import numpy.ma as ma
>>> a = np.arange(5, dtype=float)
>>> a[2] = np.NaN
>>> a[3] = np.PINF
>>> a
array([ 0., 1., nan, inf, 4.])
>>> ma.masked_invalid(a)
masked_array(data=[0.0, 1.0, --, --, 4.0],
mask=[False, False, True, True, False],
fill_value=1e+20) | numpy.reference.generated.numpy.ma.masked_invalid |
numpy.ma.masked_less ma.masked_less(x, value, copy=True)[source]
Mask an array where less than a given value. This function is a shortcut to masked_where, with condition = (x < value). See also masked_where
Mask where a condition is met. Examples >>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_less(a, 2)
masked_array(data=[--, --, 2, 3],
mask=[ True, True, False, False],
fill_value=999999) | numpy.reference.generated.numpy.ma.masked_less |
numpy.ma.masked_less_equal ma.masked_less_equal(x, value, copy=True)[source]
Mask an array where less than or equal to a given value. This function is a shortcut to masked_where, with condition = (x <= value). See also masked_where
Mask where a condition is met. Examples >>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_less_equal(a, 2)
masked_array(data=[--, --, --, 3],
mask=[ True, True, True, False],
fill_value=999999) | numpy.reference.generated.numpy.ma.masked_less_equal |
numpy.ma.masked_not_equal ma.masked_not_equal(x, value, copy=True)[source]
Mask an array where not equal to a given value. This function is a shortcut to masked_where, with condition = (x != value). See also masked_where
Mask where a condition is met. Examples >>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_not_equal(a, 2)
masked_array(data=[--, --, 2, --],
mask=[ True, True, False, True],
fill_value=999999) | numpy.reference.generated.numpy.ma.masked_not_equal |
numpy.ma.masked_object ma.masked_object(x, value, copy=True, shrink=True)[source]
Mask the array x where the data are exactly equal to value. This function is similar to masked_values, but only suitable for object arrays: for floating point, use masked_values instead. Parameters
xarray_like
Array to mask
valueobject
Comparison value
copy{True, False}, optional
Whether to return a copy of x.
shrink{True, False}, optional
Whether to collapse a mask full of False to nomask Returns
resultMaskedArray
The result of masking x where equal to value. See also masked_where
Mask where a condition is met. masked_equal
Mask where equal to a given value (integers). masked_values
Mask using floating point equality. Examples >>> import numpy.ma as ma
>>> food = np.array(['green_eggs', 'ham'], dtype=object)
>>> # don't eat spoiled food
>>> eat = ma.masked_object(food, 'green_eggs')
>>> eat
masked_array(data=[--, 'ham'],
mask=[ True, False],
fill_value='green_eggs',
dtype=object)
>>> # plain ol` ham is boring
>>> fresh_food = np.array(['cheese', 'ham', 'pineapple'], dtype=object)
>>> eat = ma.masked_object(fresh_food, 'green_eggs')
>>> eat
masked_array(data=['cheese', 'ham', 'pineapple'],
mask=False,
fill_value='green_eggs',
dtype=object)
Note that mask is set to nomask if possible. >>> eat
masked_array(data=['cheese', 'ham', 'pineapple'],
mask=False,
fill_value='green_eggs',
dtype=object) | numpy.reference.generated.numpy.ma.masked_object |
numpy.ma.masked_outside ma.masked_outside(x, v1, v2, copy=True)[source]
Mask an array outside a given interval. Shortcut to masked_where, where condition is True for x outside the interval [v1,v2] (x < v1)|(x > v2). The boundaries v1 and v2 can be given in either order. See also masked_where
Mask where a condition is met. Notes The array x is prefilled with its filling value. Examples >>> import numpy.ma as ma
>>> x = [0.31, 1.2, 0.01, 0.2, -0.4, -1.1]
>>> ma.masked_outside(x, -0.3, 0.3)
masked_array(data=[--, --, 0.01, 0.2, --, --],
mask=[ True, True, False, False, True, True],
fill_value=1e+20)
The order of v1 and v2 doesn’t matter. >>> ma.masked_outside(x, 0.3, -0.3)
masked_array(data=[--, --, 0.01, 0.2, --, --],
mask=[ True, True, False, False, True, True],
fill_value=1e+20) | numpy.reference.generated.numpy.ma.masked_outside |
numpy.ma.masked_values ma.masked_values(x, value, rtol=1e-05, atol=1e-08, copy=True, shrink=True)[source]
Mask using floating point equality. Return a MaskedArray, masked where the data in array x are approximately equal to value, determined using isclose. The default tolerances for masked_values are the same as those for isclose. For integer types, exact equality is used, in the same way as masked_equal. The fill_value is set to value and the mask is set to nomask if possible. Parameters
xarray_like
Array to mask.
valuefloat
Masking value.
rtol, atolfloat, optional
Tolerance parameters passed on to isclose
copybool, optional
Whether to return a copy of x.
shrinkbool, optional
Whether to collapse a mask full of False to nomask. Returns
resultMaskedArray
The result of masking x where approximately equal to value. See also masked_where
Mask where a condition is met. masked_equal
Mask where equal to a given value (integers). Examples >>> import numpy.ma as ma
>>> x = np.array([1, 1.1, 2, 1.1, 3])
>>> ma.masked_values(x, 1.1)
masked_array(data=[1.0, --, 2.0, --, 3.0],
mask=[False, True, False, True, False],
fill_value=1.1)
Note that mask is set to nomask if possible. >>> ma.masked_values(x, 1.5)
masked_array(data=[1. , 1.1, 2. , 1.1, 3. ],
mask=False,
fill_value=1.5)
For integers, the fill value will be different in general to the result of masked_equal. >>> x = np.arange(5)
>>> x
array([0, 1, 2, 3, 4])
>>> ma.masked_values(x, 2)
masked_array(data=[0, 1, --, 3, 4],
mask=[False, False, True, False, False],
fill_value=2)
>>> ma.masked_equal(x, 2)
masked_array(data=[0, 1, --, 3, 4],
mask=[False, False, True, False, False],
fill_value=2) | numpy.reference.generated.numpy.ma.masked_values |
numpy.ma.masked_where ma.masked_where(condition, a, copy=True)[source]
Mask an array where a condition is met. Return a as an array masked where condition is True. Any masked values of a or condition are also masked in the output. Parameters
conditionarray_like
Masking condition. When condition tests floating point values for equality, consider using masked_values instead.
aarray_like
Array to mask.
copybool
If True (default) make a copy of a in the result. If False modify a in place and return a view. Returns
resultMaskedArray
The result of masking a where condition is True. See also masked_values
Mask using floating point equality. masked_equal
Mask where equal to a given value. masked_not_equal
Mask where not equal to a given value. masked_less_equal
Mask where less than or equal to a given value. masked_greater_equal
Mask where greater than or equal to a given value. masked_less
Mask where less than a given value. masked_greater
Mask where greater than a given value. masked_inside
Mask inside a given interval. masked_outside
Mask outside a given interval. masked_invalid
Mask invalid values (NaNs or infs). Examples >>> import numpy.ma as ma
>>> a = np.arange(4)
>>> a
array([0, 1, 2, 3])
>>> ma.masked_where(a <= 2, a)
masked_array(data=[--, --, --, 3],
mask=[ True, True, True, False],
fill_value=999999)
Mask array b conditional on a. >>> b = ['a', 'b', 'c', 'd']
>>> ma.masked_where(a == 2, b)
masked_array(data=['a', 'b', --, 'd'],
mask=[False, False, True, False],
fill_value='N/A',
dtype='<U1')
Effect of the copy argument. >>> c = ma.masked_where(a <= 2, a)
>>> c
masked_array(data=[--, --, --, 3],
mask=[ True, True, True, False],
fill_value=999999)
>>> c[0] = 99
>>> c
masked_array(data=[99, --, --, 3],
mask=[False, True, True, False],
fill_value=999999)
>>> a
array([0, 1, 2, 3])
>>> c = ma.masked_where(a <= 2, a, copy=False)
>>> c[0] = 99
>>> c
masked_array(data=[99, --, --, 3],
mask=[False, True, True, False],
fill_value=999999)
>>> a
array([99, 1, 2, 3])
When condition or a contain masked values. >>> a = np.arange(4)
>>> a = ma.masked_where(a == 2, a)
>>> a
masked_array(data=[0, 1, --, 3],
mask=[False, False, True, False],
fill_value=999999)
>>> b = np.arange(4)
>>> b = ma.masked_where(b == 0, b)
>>> b
masked_array(data=[--, 1, 2, 3],
mask=[ True, False, False, False],
fill_value=999999)
>>> ma.masked_where(a == 3, b)
masked_array(data=[--, 1, --, --],
mask=[ True, False, True, True],
fill_value=999999) | numpy.reference.generated.numpy.ma.masked_where |
numpy.ma.MaskedArray.__abs__ method ma.MaskedArray.__abs__(self) | numpy.reference.generated.numpy.ma.maskedarray.__abs__ |
numpy.ma.MaskedArray.__add__ method ma.MaskedArray.__add__(other)[source]
Add self to other, and return a new masked array. | numpy.reference.generated.numpy.ma.maskedarray.__add__ |
numpy.ma.MaskedArray.__and__ method ma.MaskedArray.__and__(value, /)
Return self&value. | numpy.reference.generated.numpy.ma.maskedarray.__and__ |
numpy.ma.MaskedArray.__array__ method ma.MaskedArray.__array__([dtype, ]/) → reference if type unchanged, copy otherwise.
Returns either a new reference to self if dtype is not given or a new array of provided data type if dtype is different from the current dtype of the array. | numpy.reference.generated.numpy.ma.maskedarray.__array__ |
numpy.ma.MaskedArray.__array_priority__ attribute ma.MaskedArray.__array_priority__ = 15 | numpy.reference.generated.numpy.ma.maskedarray.__array_priority__ |
numpy.ma.MaskedArray.__array_wrap__ method ma.MaskedArray.__array_wrap__(obj, context=None)[source]
Special hook for ufuncs. Wraps the numpy array and sets the mask according to context. | numpy.reference.generated.numpy.ma.maskedarray.__array_wrap__ |
numpy.ma.MaskedArray.__bool__ method ma.MaskedArray.__bool__(/)
self != 0 | numpy.reference.generated.numpy.ma.maskedarray.__bool__ |
numpy.ma.MaskedArray.__contains__ method ma.MaskedArray.__contains__(key, /)
Return key in self. | numpy.reference.generated.numpy.ma.maskedarray.__contains__ |
numpy.ma.MaskedArray.__copy__ method ma.MaskedArray.__copy__()
Used if copy.copy is called on an array. Returns a copy of the array. Equivalent to a.copy(order='K'). | numpy.reference.generated.numpy.ma.maskedarray.__copy__ |
numpy.ma.MaskedArray.__deepcopy__ method ma.MaskedArray.__deepcopy__(memo, /) → Deep copy of array.[source]
Used if copy.deepcopy is called on an array. | numpy.reference.generated.numpy.ma.maskedarray.__deepcopy__ |
numpy.ma.MaskedArray.__delitem__ method ma.MaskedArray.__delitem__(key, /)
Delete self[key]. | numpy.reference.generated.numpy.ma.maskedarray.__delitem__ |
numpy.ma.MaskedArray.__div__ method ma.MaskedArray.__div__(other)[source]
Divide other into self, and return a new masked array. | numpy.reference.generated.numpy.ma.maskedarray.__div__ |
numpy.ma.MaskedArray.__divmod__ method ma.MaskedArray.__divmod__(value, /)
Return divmod(self, value). | numpy.reference.generated.numpy.ma.maskedarray.__divmod__ |
numpy.ma.MaskedArray.__eq__ method ma.MaskedArray.__eq__(other)[source]
Check whether other equals self elementwise. When either of the elements is masked, the result is masked as well, but the underlying boolean data are still set, with self and other considered equal if both are masked, and unequal otherwise. For structured arrays, all fields are combined, with masked values ignored. The result is masked if all fields were masked, with self and other considered equal only if both were fully masked. | numpy.reference.generated.numpy.ma.maskedarray.__eq__ |
numpy.ma.MaskedArray.__float__ method ma.MaskedArray.__float__()[source]
Convert to float. | numpy.reference.generated.numpy.ma.maskedarray.__float__ |
numpy.ma.MaskedArray.__floordiv__ method ma.MaskedArray.__floordiv__(other)[source]
Divide other into self, and return a new masked array. | numpy.reference.generated.numpy.ma.maskedarray.__floordiv__ |
numpy.ma.MaskedArray.__ge__ method ma.MaskedArray.__ge__(value, /)
Return self>=value. | numpy.reference.generated.numpy.ma.maskedarray.__ge__ |
numpy.ma.MaskedArray.__getitem__ method ma.MaskedArray.__getitem__(indx)[source]
x.__getitem__(y) <==> x[y] Return the item described by i, as a masked array. | numpy.reference.generated.numpy.ma.maskedarray.__getitem__ |
numpy.ma.MaskedArray.__getstate__ method ma.MaskedArray.__getstate__()[source]
Return the internal state of the masked array, for pickling purposes. | numpy.reference.generated.numpy.ma.maskedarray.__getstate__ |
numpy.ma.MaskedArray.__gt__ method ma.MaskedArray.__gt__(value, /)
Return self>value. | numpy.reference.generated.numpy.ma.maskedarray.__gt__ |
numpy.ma.MaskedArray.__iadd__ method ma.MaskedArray.__iadd__(other)[source]
Add other to self in-place. | numpy.reference.generated.numpy.ma.maskedarray.__iadd__ |
numpy.ma.MaskedArray.__iand__ method ma.MaskedArray.__iand__(value, /)
Return self&=value. | numpy.reference.generated.numpy.ma.maskedarray.__iand__ |
numpy.ma.MaskedArray.__idiv__ method ma.MaskedArray.__idiv__(other)[source]
Divide self by other in-place. | numpy.reference.generated.numpy.ma.maskedarray.__idiv__ |
numpy.ma.MaskedArray.__ifloordiv__ method ma.MaskedArray.__ifloordiv__(other)[source]
Floor divide self by other in-place. | numpy.reference.generated.numpy.ma.maskedarray.__ifloordiv__ |
numpy.ma.MaskedArray.__ilshift__ method ma.MaskedArray.__ilshift__(value, /)
Return self<<=value. | numpy.reference.generated.numpy.ma.maskedarray.__ilshift__ |
numpy.ma.MaskedArray.__imod__ method ma.MaskedArray.__imod__(value, /)
Return self%=value. | numpy.reference.generated.numpy.ma.maskedarray.__imod__ |
numpy.ma.MaskedArray.__imul__ method ma.MaskedArray.__imul__(other)[source]
Multiply self by other in-place. | numpy.reference.generated.numpy.ma.maskedarray.__imul__ |
numpy.ma.MaskedArray.__int__ method ma.MaskedArray.__int__()[source]
Convert to int. | numpy.reference.generated.numpy.ma.maskedarray.__int__ |
numpy.ma.MaskedArray.__ior__ method ma.MaskedArray.__ior__(value, /)
Return self|=value. | numpy.reference.generated.numpy.ma.maskedarray.__ior__ |
numpy.ma.MaskedArray.__ipow__ method ma.MaskedArray.__ipow__(other)[source]
Raise self to the power other, in place. | numpy.reference.generated.numpy.ma.maskedarray.__ipow__ |
numpy.ma.MaskedArray.__irshift__ method ma.MaskedArray.__irshift__(value, /)
Return self>>=value. | numpy.reference.generated.numpy.ma.maskedarray.__irshift__ |
numpy.ma.MaskedArray.__isub__ method ma.MaskedArray.__isub__(other)[source]
Subtract other from self in-place. | numpy.reference.generated.numpy.ma.maskedarray.__isub__ |
numpy.ma.MaskedArray.__itruediv__ method ma.MaskedArray.__itruediv__(other)[source]
True divide self by other in-place. | numpy.reference.generated.numpy.ma.maskedarray.__itruediv__ |
numpy.ma.MaskedArray.__ixor__ method ma.MaskedArray.__ixor__(value, /)
Return self^=value. | numpy.reference.generated.numpy.ma.maskedarray.__ixor__ |
numpy.ma.MaskedArray.__le__ method ma.MaskedArray.__le__(value, /)
Return self<=value. | numpy.reference.generated.numpy.ma.maskedarray.__le__ |
numpy.ma.MaskedArray.__len__ method ma.MaskedArray.__len__(/)
Return len(self). | numpy.reference.generated.numpy.ma.maskedarray.__len__ |
numpy.ma.MaskedArray.__lshift__ method ma.MaskedArray.__lshift__(value, /)
Return self<<value. | numpy.reference.generated.numpy.ma.maskedarray.__lshift__ |
numpy.ma.MaskedArray.__lt__ method ma.MaskedArray.__lt__(value, /)
Return self<value. | numpy.reference.generated.numpy.ma.maskedarray.__lt__ |
numpy.ma.MaskedArray.__mod__ method ma.MaskedArray.__mod__(value, /)
Return self%value. | numpy.reference.generated.numpy.ma.maskedarray.__mod__ |
numpy.ma.MaskedArray.__mul__ method ma.MaskedArray.__mul__(other)[source]
Multiply self by other, and return a new masked array. | numpy.reference.generated.numpy.ma.maskedarray.__mul__ |
numpy.ma.MaskedArray.__ne__ method ma.MaskedArray.__ne__(other)[source]
Check whether other does not equal self elementwise. When either of the elements is masked, the result is masked as well, but the underlying boolean data are still set, with self and other considered equal if both are masked, and unequal otherwise. For structured arrays, all fields are combined, with masked values ignored. The result is masked if all fields were masked, with self and other considered equal only if both were fully masked. | numpy.reference.generated.numpy.ma.maskedarray.__ne__ |
numpy.ma.MaskedArray.__or__ method ma.MaskedArray.__or__(value, /)
Return self|value. | numpy.reference.generated.numpy.ma.maskedarray.__or__ |
numpy.ma.MaskedArray.__pow__ method ma.MaskedArray.__pow__(other)[source]
Raise self to the power other, masking the potential NaNs/Infs | numpy.reference.generated.numpy.ma.maskedarray.__pow__ |
numpy.ma.MaskedArray.__radd__ method ma.MaskedArray.__radd__(other)[source]
Add other to self, and return a new masked array. | numpy.reference.generated.numpy.ma.maskedarray.__radd__ |
numpy.ma.MaskedArray.__rand__ method ma.MaskedArray.__rand__(value, /)
Return value&self. | numpy.reference.generated.numpy.ma.maskedarray.__rand__ |
numpy.ma.MaskedArray.__rdivmod__ method ma.MaskedArray.__rdivmod__(value, /)
Return divmod(value, self). | numpy.reference.generated.numpy.ma.maskedarray.__rdivmod__ |
numpy.ma.MaskedArray.__reduce__ method ma.MaskedArray.__reduce__()[source]
Return a 3-tuple for pickling a MaskedArray. | numpy.reference.generated.numpy.ma.maskedarray.__reduce__ |
numpy.ma.MaskedArray.__repr__ method ma.MaskedArray.__repr__()[source]
Literal string representation. | numpy.reference.generated.numpy.ma.maskedarray.__repr__ |
numpy.ma.MaskedArray.__rfloordiv__ method ma.MaskedArray.__rfloordiv__(other)[source]
Divide self into other, and return a new masked array. | numpy.reference.generated.numpy.ma.maskedarray.__rfloordiv__ |
numpy.ma.MaskedArray.__rlshift__ method ma.MaskedArray.__rlshift__(value, /)
Return value<<self. | numpy.reference.generated.numpy.ma.maskedarray.__rlshift__ |
numpy.ma.MaskedArray.__rmod__ method ma.MaskedArray.__rmod__(value, /)
Return value%self. | numpy.reference.generated.numpy.ma.maskedarray.__rmod__ |
numpy.ma.MaskedArray.__rmul__ method ma.MaskedArray.__rmul__(other)[source]
Multiply other by self, and return a new masked array. | numpy.reference.generated.numpy.ma.maskedarray.__rmul__ |
numpy.ma.MaskedArray.__ror__ method ma.MaskedArray.__ror__(value, /)
Return value|self. | numpy.reference.generated.numpy.ma.maskedarray.__ror__ |
Subsets and Splits