numpy.ma.MaskedArray.ctypes attribute   ma.MaskedArray.ctypes

An object to simplify the interaction of the array with the ctypes module. This attribute creates an object that makes it easier to use arrays when calling shared libraries with the ctypes module. The returned object has, among others, data, shape, and strides attributes (see Notes below) which themselves return ctypes objects that can be used as arguments to a shared library.  Parameters
 None
  Returns

cPython object

Possessing attributes data, shape, strides, etc.      See also  numpy.ctypeslib
  Notes Below are the public attributes of this object which were documented in “Guide to NumPy” (we have omitted undocumented public attributes, as well as documented private attributes):   _ctypes.data

A pointer to the memory area of the array as a Python integer. This memory area may contain data that is not aligned, or not in correct byte-order. The memory area may not even be writeable. The array flags and data-type of this array should be respected when passing this attribute to arbitrary C-code to avoid trouble that can include Python crashing. User Beware! The value of this attribute is exactly the same as self._array_interface_['data'][0]. Note that unlike data_as, a reference will not be kept to the array: code like ctypes.c_void_p((a + b).ctypes.data) will result in a pointer to a deallocated array, and should be spelt (a + b).ctypes.data_as(ctypes.c_void_p)
   _ctypes.shape

(c_intp*self.ndim): A ctypes array of length self.ndim where the basetype is the C-integer corresponding to dtype('p') on this platform (see c_intp). This base-type could be ctypes.c_int, ctypes.c_long, or ctypes.c_longlong depending on the platform. The ctypes array contains the shape of the underlying array.
   _ctypes.strides

(c_intp*self.ndim): A ctypes array of length self.ndim where the basetype is the same as for the shape attribute. This ctypes array contains the strides information from the underlying array. This strides information is important for showing how many bytes must be jumped to get to the next element in the array.
   _ctypes.data_as(obj)[source]

Return the data pointer cast to a particular c-types object. For example, calling self._as_parameter_ is equivalent to self.data_as(ctypes.c_void_p). Perhaps you want to use the data as a pointer to a ctypes array of floating-point data: self.data_as(ctypes.POINTER(ctypes.c_double)). The returned pointer will keep a reference to the array.
   _ctypes.shape_as(obj)[source]

Return the shape tuple as an array of some other c-types type. For example: self.shape_as(ctypes.c_short).
   _ctypes.strides_as(obj)[source]

Return the strides tuple as an array of some other c-types type. For example: self.strides_as(ctypes.c_longlong).
 If the ctypes module is not available, then the ctypes attribute of array objects still returns something useful, but ctypes objects are not returned and errors may be raised instead. In particular, the object will still have the as_parameter attribute which will return an integer equal to the data attribute. Examples >>> import ctypes
>>> x = np.array([[0, 1], [2, 3]], dtype=np.int32)
>>> x
array([[0, 1],
       [2, 3]], dtype=int32)
>>> x.ctypes.data
31962608 # may vary
>>> x.ctypes.data_as(ctypes.POINTER(ctypes.c_uint32))
<__main__.LP_c_uint object at 0x7ff2fc1fc200> # may vary
>>> x.ctypes.data_as(ctypes.POINTER(ctypes.c_uint32)).contents
c_uint(0)
>>> x.ctypes.data_as(ctypes.POINTER(ctypes.c_uint64)).contents
c_ulong(4294967296)
>>> x.ctypes.shape
<numpy.core._internal.c_long_Array_2 object at 0x7ff2fc1fce60> # may vary
>>> x.ctypes.strides
<numpy.core._internal.c_long_Array_2 object at 0x7ff2fc1ff320> # may vary


numpy.ma.MaskedArray.cumprod method   ma.MaskedArray.cumprod(axis=None, dtype=None, out=None)[source]

Return the cumulative product of the array elements over the given axis. Masked values are set to 1 internally during the computation. However, their position is saved, and the result will be masked at the same locations. Refer to numpy.cumprod for full documentation.  See also  numpy.ndarray.cumprod

corresponding function for ndarrays  numpy.cumprod

equivalent function    Notes The mask is lost if out is not a valid MaskedArray ! Arithmetic is modular when using integer types, and no error is raised on overflow.


numpy.ma.MaskedArray.cumsum method   ma.MaskedArray.cumsum(axis=None, dtype=None, out=None)[source]

Return the cumulative sum of the array elements over the given axis. Masked values are set to 0 internally during the computation. However, their position is saved, and the result will be masked at the same locations. Refer to numpy.cumsum for full documentation.  See also  numpy.ndarray.cumsum

corresponding function for ndarrays  numpy.cumsum

equivalent function    Notes The mask is lost if out is not a valid ma.MaskedArray ! Arithmetic is modular when using integer types, and no error is raised on overflow. Examples >>> marr = np.ma.array(np.arange(10), mask=[0,0,0,1,1,1,0,0,0,0])
>>> marr.cumsum()
masked_array(data=[0, 1, 3, --, --, --, 9, 16, 24, 33],
             mask=[False, False, False,  True,  True,  True, False, False,
                   False, False],
       fill_value=999999)


numpy.ma.MaskedArray.diagonal method   ma.MaskedArray.diagonal(offset=0, axis1=0, axis2=1)[source]

Return specified diagonals. In NumPy 1.9 the returned array is a read-only view instead of a copy as in previous NumPy versions. In a future version the read-only restriction will be removed. Refer to numpy.diagonal for full documentation.  See also  numpy.diagonal

equivalent function


numpy.ma.MaskedArray.dump method   ma.MaskedArray.dump(file)

Dump a pickle of the array to the specified file. The array can be read back with pickle.load or numpy.load.  Parameters

filestr or Path

A string naming the dump file.  Changed in version 1.17.0: pathlib.Path objects are now accepted.


numpy.ma.MaskedArray.dumps method   ma.MaskedArray.dumps()

Returns the pickle of the array as a string. pickle.loads will convert the string back to an array.  Parameters
 None


numpy.ma.MaskedArray.fill method   ma.MaskedArray.fill(value)

Fill the array with a scalar value.  Parameters

valuescalar

All elements of a will be assigned this value.     Examples >>> a = np.array([1, 2])
>>> a.fill(0)
>>> a
array([0, 0])
>>> a = np.empty(2)
>>> a.fill(1)
>>> a
array([1.,  1.])


numpy.ma.MaskedArray.filled method   ma.MaskedArray.filled(fill_value=None)[source]

Return a copy of self, with masked values filled with a given value. However, if there are no masked values to fill, self will be returned instead as an ndarray.  Parameters

fill_valuearray_like, optional

The value to use for invalid entries. Can be scalar or non-scalar. If non-scalar, the resulting ndarray must be broadcastable over input array. Default is None, in which case, the fill_value attribute of the array is used instead.    Returns

filled_arrayndarray

A copy of self with invalid entries replaced by fill_value (be it the function argument or the attribute of self), or self itself as an ndarray if there are no invalid entries to be replaced.     Notes The result is not a MaskedArray! Examples >>> x = np.ma.array([1,2,3,4,5], mask=[0,0,1,0,1], fill_value=-999)
>>> x.filled()
array([   1,    2, -999,    4, -999])
>>> x.filled(fill_value=1000)
array([   1,    2, 1000,    4, 1000])
>>> type(x.filled())
<class 'numpy.ndarray'>
 Subclassing is preserved. This means that if, e.g., the data part of the masked array is a recarray, filled returns a recarray: >>> x = np.array([(-1, 2), (-3, 4)], dtype='i8,i8').view(np.recarray)
>>> m = np.ma.array(x, mask=[(True, False), (False, True)])
>>> m.filled()
rec.array([(999999,      2), (    -3, 999999)],
          dtype=[('f0', '<i8'), ('f1', '<i8')])


numpy.ma.MaskedArray.flags attribute   ma.MaskedArray.flags

Information about the memory layout of the array. Notes The flags object can be accessed dictionary-like (as in a.flags['WRITEABLE']), or by using lowercased attribute names (as in a.flags.writeable). Short flag names are only supported in dictionary access. Only the WRITEBACKIFCOPY, UPDATEIFCOPY, WRITEABLE, and ALIGNED flags can be changed by the user, via direct assignment to the attribute or dictionary entry, or by calling ndarray.setflags. The array flags cannot be set arbitrarily:  UPDATEIFCOPY can only be set False. WRITEBACKIFCOPY can only be set False. ALIGNED can only be set True if the data is truly aligned. WRITEABLE can only be set True if the array owns its own memory or the ultimate owner of the memory exposes a writeable buffer interface or is a string.  Arrays can be both C-style and Fortran-style contiguous simultaneously. This is clear for 1-dimensional arrays, but can also be true for higher dimensional arrays. Even for contiguous arrays a stride for a given dimension arr.strides[dim] may be arbitrary if arr.shape[dim] == 1 or the array has no elements. It does not generally hold that self.strides[-1] == self.itemsize for C-style contiguous arrays or self.strides[0] == self.itemsize for Fortran-style contiguous arrays is true.  Attributes
 C_CONTIGUOUS (C)

The data is in a single, C-style contiguous segment.  F_CONTIGUOUS (F)

The data is in a single, Fortran-style contiguous segment.  OWNDATA (O)

The array owns the memory it uses or borrows it from another object.  WRITEABLE (W)

The data area can be written to. Setting this to False locks the data, making it read-only. A view (slice, etc.) inherits WRITEABLE from its base array at creation time, but a view of a writeable array may be subsequently locked while the base array remains writeable. (The opposite is not true, in that a view of a locked array may not be made writeable. However, currently, locking a base object does not lock any views that already reference it, so under that circumstance it is possible to alter the contents of a locked array via a previously created writeable view onto it.) Attempting to change a non-writeable array raises a RuntimeError exception.  ALIGNED (A)

The data and all elements are aligned appropriately for the hardware.  WRITEBACKIFCOPY (X)

This array is a copy of some other array. The C-API function PyArray_ResolveWritebackIfCopy must be called before deallocating to the base array will be updated with the contents of this array.  UPDATEIFCOPY (U)

(Deprecated, use WRITEBACKIFCOPY) This array is a copy of some other array. When this array is deallocated, the base array will be updated with the contents of this array.  FNC

F_CONTIGUOUS and not C_CONTIGUOUS.  FORC

F_CONTIGUOUS or C_CONTIGUOUS (one-segment test).  BEHAVED (B)

ALIGNED and WRITEABLE.  CARRAY (CA)

BEHAVED and C_CONTIGUOUS.  FARRAY (FA)

BEHAVED and F_CONTIGUOUS and not C_CONTIGUOUS.


numpy.ma.MaskedArray.flatten method   ma.MaskedArray.flatten(order='C')[source]

Return a copy of the array collapsed into one dimension.  Parameters

order{‘C’, ‘F’, ‘A’, ‘K’}, optional

‘C’ means to flatten in row-major (C-style) order. ‘F’ means to flatten in column-major (Fortran- style) order. ‘A’ means to flatten in column-major order if a is Fortran contiguous in memory, row-major order otherwise. ‘K’ means to flatten a in the order the elements occur in memory. The default is ‘C’.    Returns

yndarray

A copy of the input array, flattened to one dimension.      See also  ravel

Return a flattened array.  flat

A 1-D flat iterator over the array.    Examples >>> a = np.array([[1,2], [3,4]])
>>> a.flatten()
array([1, 2, 3, 4])
>>> a.flatten('F')
array([1, 3, 2, 4])


numpy.ma.MaskedArray.get_fill_value method   ma.MaskedArray.get_fill_value()[source]

The filling value of the masked array is a scalar. When setting, None will set to a default based on the data type. Examples >>> for dt in [np.int32, np.int64, np.float64, np.complex128]:
...     np.ma.array([0, 1], dtype=dt).get_fill_value()
...
999999
999999
1e+20
(1e+20+0j)
 >>> x = np.ma.array([0, 1.], fill_value=-np.inf)
>>> x.fill_value
-inf
>>> x.fill_value = np.pi
>>> x.fill_value
3.1415926535897931 # may vary
 Reset to default: >>> x.fill_value = None
>>> x.fill_value
1e+20


numpy.ma.MaskedArray.harden_mask method   ma.MaskedArray.harden_mask()[source]

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.ma.MaskedArray.ids method   ma.MaskedArray.ids()[source]

Return the addresses of the data and mask areas.  Parameters
 None
   Examples >>> x = np.ma.array([1, 2, 3], mask=[0, 1, 1])
>>> x.ids()
(166670640, 166659832) # may vary
 If the array has no mask, the address of nomask is returned. This address is typically not close to the data in memory: >>> x = np.ma.array([1, 2, 3])
>>> x.ids()
(166691080, 3083169284) # may vary


numpy.ma.MaskedArray.iscontiguous method   ma.MaskedArray.iscontiguous()[source]

Return a boolean indicating whether the data is contiguous.  Parameters
 None
   Examples >>> x = np.ma.array([1, 2, 3])
>>> x.iscontiguous()
True
 iscontiguous returns one of the flags of the masked array: >>> x.flags
  C_CONTIGUOUS : True
  F_CONTIGUOUS : True
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  WRITEBACKIFCOPY : False
  UPDATEIFCOPY : False


numpy.ma.MaskedArray.item method   ma.MaskedArray.item(*args)

Copy an element of an array to a standard Python scalar and return it.  Parameters

*argsArguments (variable number and type)

 none: in this case, the method only works for arrays with one element (a.size == 1), which element is copied into a standard Python scalar object and returned. int_type: this argument is interpreted as a flat index into the array, specifying which element to copy and return. tuple of int_types: functions as does a single int_type argument, except that the argument is interpreted as an nd-index into the array.     Returns

zStandard Python scalar object

A copy of the specified element of the array as a suitable Python scalar     Notes When the data type of a is longdouble or clongdouble, item() returns a scalar array object because there is no available Python scalar that would not lose information. Void arrays return a buffer object for item(), unless fields are defined, in which case a tuple is returned. item is very similar to a[args], except, instead of an array scalar, a standard Python scalar is returned. This can be useful for speeding up access to elements of the array and doing arithmetic on elements of the array using Python’s optimized math. Examples >>> np.random.seed(123)
>>> x = np.random.randint(9, size=(3, 3))
>>> x
array([[2, 2, 6],
       [1, 3, 6],
       [1, 0, 1]])
>>> x.item(3)
1
>>> x.item(7)
0
>>> x.item((0, 1))
2
>>> x.item((2, 2))
1


numpy.ma.MaskedArray.itemsize attribute   ma.MaskedArray.itemsize

Length of one array element in bytes. Examples >>> x = np.array([1,2,3], dtype=np.float64)
>>> x.itemsize
8
>>> x = np.array([1,2,3], dtype=np.complex128)
>>> x.itemsize
16


numpy.ma.MaskedArray.max method   ma.MaskedArray.max(axis=None, out=None, fill_value=None, keepdims=<no value>)[source]

Return the maximum along a given axis.  Parameters

axis{None, int}, optional

Axis along which to operate. By default, axis is None and the flattened input is used.
outarray_like, optional

Alternative output array in which to place the result. Must be of the same shape and buffer length as the expected output.
fill_valuescalar or None, optional

Value used to fill in the masked values. If None, use the output of maximum_fill_value().
keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the array.    Returns

amaxarray_like

New array holding the result. If out was specified, out is returned.      See also  ma.maximum_fill_value

Returns the maximum filling value for a given datatype.


numpy.ma.MaskedArray.mean method   ma.MaskedArray.mean(axis=None, dtype=None, out=None, keepdims=<no value>)[source]

Returns the average of the array elements along given axis. Masked entries are ignored, and result elements which are not finite will be masked. Refer to numpy.mean for full documentation.  See also  numpy.ndarray.mean

corresponding function for ndarrays  numpy.mean

Equivalent function  numpy.ma.average

Weighted average.    Examples >>> a = np.ma.array([1,2,3], mask=[False, False, True])
>>> a
masked_array(data=[1, 2, --],
             mask=[False, False,  True],
       fill_value=999999)
>>> a.mean()
1.5


numpy.ma.MaskedArray.min method   ma.MaskedArray.min(axis=None, out=None, fill_value=None, keepdims=<no value>)[source]

Return the minimum along a given axis.  Parameters

axis{None, int}, optional

Axis along which to operate. By default, axis is None and the flattened input is used.
outarray_like, optional

Alternative output array in which to place the result. Must be of the same shape and buffer length as the expected output.
fill_valuescalar or None, optional

Value used to fill in the masked values. If None, use the output of minimum_fill_value.
keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the array.    Returns

aminarray_like

New array holding the result. If out was specified, out is returned.      See also  ma.minimum_fill_value

Returns the minimum filling value for a given datatype.


numpy.ma.MaskedArray.nbytes attribute   ma.MaskedArray.nbytes

Total bytes consumed by the elements of the array. Notes Does not include memory consumed by non-element attributes of the array object. Examples >>> x = np.zeros((3,5,2), dtype=np.complex128)
>>> x.nbytes
480
>>> np.prod(x.shape) * x.itemsize
480


numpy.ma.MaskedArray.ndim attribute   ma.MaskedArray.ndim

Number of array dimensions. Examples >>> x = np.array([1, 2, 3])
>>> x.ndim
1
>>> y = np.zeros((2, 3, 4))
>>> y.ndim
3


numpy.ma.MaskedArray.nonzero method   ma.MaskedArray.nonzero()[source]

Return the indices of unmasked elements that are not zero. Returns a tuple of arrays, one for each dimension, containing the indices of the non-zero elements in that dimension. The corresponding non-zero values can be obtained with: a[a.nonzero()]
 To group the indices by element, rather than dimension, use instead: np.transpose(a.nonzero())
 The result of this is always a 2d array, with a row for each non-zero element.  Parameters
 None
  Returns

tuple_of_arraystuple

Indices of elements that are non-zero.      See also  numpy.nonzero

Function operating on ndarrays.  flatnonzero

Return indices that are non-zero in the flattened version of the input array.  numpy.ndarray.nonzero

Equivalent ndarray method.  count_nonzero

Counts the number of non-zero elements in the input array.    Examples >>> import numpy.ma as ma
>>> x = ma.array(np.eye(3))
>>> x
masked_array(
  data=[[1., 0., 0.],
        [0., 1., 0.],
        [0., 0., 1.]],
  mask=False,
  fill_value=1e+20)
>>> x.nonzero()
(array([0, 1, 2]), array([0, 1, 2]))
 Masked elements are ignored. >>> x[1, 1] = ma.masked
>>> x
masked_array(
  data=[[1.0, 0.0, 0.0],
        [0.0, --, 0.0],
        [0.0, 0.0, 1.0]],
  mask=[[False, False, False],
        [False,  True, False],
        [False, False, False]],
  fill_value=1e+20)
>>> x.nonzero()
(array([0, 2]), array([0, 2]))
 Indices can also be grouped by element. >>> np.transpose(x.nonzero())
array([[0, 0],
       [2, 2]])
 A common use for nonzero is to find the indices of an array, where a condition is True. Given an array a, the condition a > 3 is a boolean array and since False is interpreted as 0, ma.nonzero(a > 3) yields the indices of the a where the condition is true. >>> a = ma.array([[1,2,3],[4,5,6],[7,8,9]])
>>> a > 3
masked_array(
  data=[[False, False, False],
        [ True,  True,  True],
        [ True,  True,  True]],
  mask=False,
  fill_value=True)
>>> ma.nonzero(a > 3)
(array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2]))
 The nonzero method of the condition array can also be called. >>> (a > 3).nonzero()
(array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2]))


numpy.ma.MaskedArray.prod method   ma.MaskedArray.prod(axis=None, dtype=None, out=None, keepdims=<no value>)[source]

Return the product of the array elements over the given axis. Masked elements are set to 1 internally for computation. Refer to numpy.prod for full documentation.  See also  numpy.ndarray.prod

corresponding function for ndarrays  numpy.prod

equivalent function    Notes Arithmetic is modular when using integer types, and no error is raised on overflow.


numpy.ma.MaskedArray.product method   ma.MaskedArray.product(axis=None, dtype=None, out=None, keepdims=<no value>)[source]

Return the product of the array elements over the given axis. Masked elements are set to 1 internally for computation. Refer to numpy.prod for full documentation.  See also  numpy.ndarray.prod

corresponding function for ndarrays  numpy.prod

equivalent function    Notes Arithmetic is modular when using integer types, and no error is raised on overflow.


numpy.ma.MaskedArray.ptp method   ma.MaskedArray.ptp(axis=None, out=None, fill_value=None, keepdims=False)[source]

Return (maximum - minimum) along the given dimension (i.e. peak-to-peak value).  Warning ptp preserves the data type of the array. This means the return value for an input of signed integers with n bits (e.g. np.int8, np.int16, etc) is also a signed integer with n bits. In that case, peak-to-peak values greater than 2**(n-1)-1 will be returned as negative values. An example with a work-around is shown below.   Parameters

axis{None, int}, optional

Axis along which to find the peaks. If None (default) the flattened array is used.
out{None, array_like}, optional

Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary.
fill_valuescalar or None, optional

Value used to fill in the masked values.
keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the array.    Returns

ptpndarray.

A new array holding the result, unless out was specified, in which case a reference to out is returned.     Examples >>> x = np.ma.MaskedArray([[4, 9, 2, 10],
...                        [6, 9, 7, 12]])
 >>> x.ptp(axis=1)
masked_array(data=[8, 6],
             mask=False,
       fill_value=999999)
 >>> x.ptp(axis=0)
masked_array(data=[2, 0, 5, 2],
             mask=False,
       fill_value=999999)
 >>> x.ptp()
10
 This example shows that a negative value can be returned when the input is an array of signed integers. >>> y = np.ma.MaskedArray([[1, 127],
...                        [0, 127],
...                        [-1, 127],
...                        [-2, 127]], dtype=np.int8)
>>> y.ptp(axis=1)
masked_array(data=[ 126,  127, -128, -127],
             mask=False,
       fill_value=999999,
            dtype=int8)
 A work-around is to use the view() method to view the result as unsigned integers with the same bit width: >>> y.ptp(axis=1).view(np.uint8)
masked_array(data=[126, 127, 128, 129],
             mask=False,
       fill_value=999999,
            dtype=uint8)


numpy.ma.MaskedArray.put method   ma.MaskedArray.put(indices, values, mode='raise')[source]

Set storage-indexed locations to corresponding values. Sets self._data.flat[n] = values[n] for each n in indices. If values is shorter than indices then it will repeat. If values has some masked values, the initial mask is updated in consequence, else the corresponding values are unmasked.  Parameters

indices1-D array_like

Target indices, interpreted as integers.
valuesarray_like

Values to place in self._data copy at target indices.
mode{‘raise’, ‘wrap’, ‘clip’}, optional

Specifies how out-of-bounds indices will behave. ‘raise’ : raise an error. ‘wrap’ : wrap around. ‘clip’ : clip to the range.     Notes values can be a scalar or length 1 array. Examples >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> x
masked_array(
  data=[[1, --, 3],
        [--, 5, --],
        [7, --, 9]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)
>>> x.put([0,4,8],[10,20,30])
>>> x
masked_array(
  data=[[10, --, 3],
        [--, 20, --],
        [7, --, 30]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)
 >>> x.put(4,999)
>>> x
masked_array(
  data=[[10, --, 3],
        [--, 999, --],
        [7, --, 30]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)


numpy.ma.MaskedArray.ravel method   ma.MaskedArray.ravel(order='C')[source]

Returns a 1D version of self, as a view.  Parameters

order{‘C’, ‘F’, ‘A’, ‘K’}, optional

The elements of a are read using this index order. ‘C’ means to index the elements in C-like order, with the last axis index changing fastest, back to the first axis index changing slowest. ‘F’ means to index the elements in Fortran-like index order, with the first index changing fastest, and the last index changing slowest. Note that the ‘C’ and ‘F’ options take no account of the memory layout of the underlying array, and only refer to the order of axis indexing. ‘A’ means to read the elements in Fortran-like index order if m is Fortran contiguous in memory, C-like order otherwise. ‘K’ means to read the elements in the order they occur in memory, except for reversing the data when strides are negative. By default, ‘C’ index order is used.    Returns
 MaskedArray

Output view is of shape (self.size,) (or (np.ma.product(self.shape),)).     Examples >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> x
masked_array(
  data=[[1, --, 3],
        [--, 5, --],
        [7, --, 9]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)
>>> x.ravel()
masked_array(data=[1, --, 3, --, 5, --, 7, --, 9],
             mask=[False,  True, False,  True, False,  True, False,  True,
                   False],
       fill_value=999999)


numpy.ma.MaskedArray.repeat method   ma.MaskedArray.repeat(repeats, axis=None)[source]

Repeat elements of an array. Refer to numpy.repeat for full documentation.  See also  numpy.repeat

equivalent function


numpy.ma.MaskedArray.reshape method   ma.MaskedArray.reshape(*s, **kwargs)[source]

Give a new shape to the array without changing its data. Returns a masked array containing the same data, but with a new shape. The result is a view on the original array; if this is not possible, a ValueError is raised.  Parameters

shapeint or tuple of ints

The new shape should be compatible with the original shape. If an integer is supplied, then the result will be a 1-D array of that length.
order{‘C’, ‘F’}, optional

Determines whether the array data should be viewed as in C (row-major) or FORTRAN (column-major) order.    Returns

reshaped_arrayarray

A new view on the array.      See also  reshape

Equivalent function in the masked array module.  numpy.ndarray.reshape

Equivalent method on ndarray object.  numpy.reshape

Equivalent function in the NumPy module.    Notes The reshaping operation cannot guarantee that a copy will not be made, to modify the shape in place, use a.shape = s Examples >>> x = np.ma.array([[1,2],[3,4]], mask=[1,0,0,1])
>>> x
masked_array(
  data=[[--, 2],
        [3, --]],
  mask=[[ True, False],
        [False,  True]],
  fill_value=999999)
>>> x = x.reshape((4,1))
>>> x
masked_array(
  data=[[--],
        [2],
        [3],
        [--]],
  mask=[[ True],
        [False],
        [False],
        [ True]],
  fill_value=999999)


numpy.ma.MaskedArray.resize method   ma.MaskedArray.resize(newshape, refcheck=True, order=False)[source]

 Warning This method does nothing, except raise a ValueError exception. A masked array does not own its data and therefore cannot safely be resized in place. Use the numpy.ma.resize function instead.  This method is difficult to implement safely and may be deprecated in future releases of NumPy.


numpy.ma.MaskedArray.round method   ma.MaskedArray.round(decimals=0, out=None)[source]

Return each element rounded to the given number of decimals. Refer to numpy.around for full documentation.  See also  numpy.ndarray.round

corresponding function for ndarrays  numpy.around

equivalent function


numpy.ma.MaskedArray.searchsorted method   ma.MaskedArray.searchsorted(v, side='left', sorter=None)

Find indices where elements of v should be inserted in a to maintain order. For full documentation, see numpy.searchsorted  See also  numpy.searchsorted

equivalent function


numpy.ma.MaskedArray.set_fill_value method   ma.MaskedArray.set_fill_value(value=None)[source]


numpy.ma.MaskedArray.shrink_mask method   ma.MaskedArray.shrink_mask()[source]

Reduce a mask to nomask when possible.  Parameters
 None
  Returns
 None
   Examples >>> x = np.ma.array([[1,2 ], [3, 4]], mask=[0]*4)
>>> x.mask
array([[False, False],
       [False, False]])
>>> x.shrink_mask()
masked_array(
  data=[[1, 2],
        [3, 4]],
  mask=False,
  fill_value=999999)
>>> x.mask
False


numpy.ma.MaskedArray.size attribute   ma.MaskedArray.size

Number of elements in the array. Equal to np.prod(a.shape), i.e., the product of the array’s dimensions. Notes a.size returns a standard arbitrary precision Python integer. This may not be the case with other methods of obtaining the same value (like the suggested np.prod(a.shape), which returns an instance of np.int_), and may be relevant if the value is used further in calculations that may overflow a fixed size integer type. Examples >>> x = np.zeros((3, 5, 2), dtype=np.complex128)
>>> x.size
30
>>> np.prod(x.shape)
30


numpy.ma.MaskedArray.soften_mask method   ma.MaskedArray.soften_mask()[source]

Force the mask to soft. Whether the mask of a masked array is hard or soft is determined by its hardmask property. soften_mask sets hardmask to False.  See also  ma.MaskedArray.hardmask


numpy.ma.MaskedArray.sort method   ma.MaskedArray.sort(axis=- 1, kind=None, order=None, endwith=True, fill_value=None)[source]

Sort the array, in-place  Parameters

aarray_like

Array to be sorted.
axisint, optional

Axis along which to sort. If None, the array is flattened before sorting. The default is -1, which sorts along the last axis.
kind{‘quicksort’, ‘mergesort’, ‘heapsort’, ‘stable’}, optional

The sorting algorithm used.
orderlist, optional

When a is a structured array, this argument specifies which fields to compare first, second, and so on. This list does not need to include all of the fields.
endwith{True, False}, optional

Whether missing values (if any) should be treated as the largest values (True) or the smallest values (False) When the array contains unmasked values sorting at the same extremes of the datatype, the ordering of these values and the masked values is undefined.
fill_valuescalar or None, optional

Value used internally for the masked values. If fill_value is not None, it supersedes endwith.    Returns

sorted_arrayndarray

Array of the same type and shape as a.      See also  numpy.ndarray.sort

Method to sort an array in-place.  argsort

Indirect sort.  lexsort

Indirect stable sort on multiple keys.  searchsorted

Find elements in a sorted array.    Notes See sort for notes on the different sorting algorithms. Examples >>> a = np.ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0])
>>> # Default
>>> a.sort()
>>> a
masked_array(data=[1, 3, 5, --, --],
             mask=[False, False, False,  True,  True],
       fill_value=999999)
 >>> a = np.ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0])
>>> # Put missing values in the front
>>> a.sort(endwith=False)
>>> a
masked_array(data=[--, --, 1, 3, 5],
             mask=[ True,  True, False, False, False],
       fill_value=999999)
 >>> a = np.ma.array([1, 2, 5, 4, 3],mask=[0, 1, 0, 1, 0])
>>> # fill_value takes over endwith
>>> a.sort(endwith=False, fill_value=3)
>>> a
masked_array(data=[1, --, --, 3, 5],
             mask=[False,  True,  True, False, False],
       fill_value=999999)


numpy.ma.MaskedArray.squeeze method   ma.MaskedArray.squeeze(axis=None)[source]

Remove axes of length one from a. Refer to numpy.squeeze for full documentation.  See also  numpy.squeeze

equivalent function


numpy.ma.MaskedArray.std method   ma.MaskedArray.std(axis=None, dtype=None, out=None, ddof=0, keepdims=<no value>)[source]

Returns the standard deviation of the array elements along given axis. Masked entries are ignored. Refer to numpy.std for full documentation.  See also  numpy.ndarray.std

corresponding function for ndarrays  numpy.std

Equivalent function


numpy.ma.MaskedArray.strides attribute   ma.MaskedArray.strides

Tuple of bytes to step in each dimension when traversing an array. The byte offset of element (i[0], i[1], ..., i[n]) in an array a is: offset = sum(np.array(i) * a.strides)
 A more detailed explanation of strides can be found in the “ndarray.rst” file in the NumPy reference guide.  See also  numpy.lib.stride_tricks.as_strided
  Notes Imagine an array of 32-bit integers (each 4 bytes): x = np.array([[0, 1, 2, 3, 4],
              [5, 6, 7, 8, 9]], dtype=np.int32)
 This array is stored in memory as 40 bytes, one after the other (known as a contiguous block of memory). The strides of an array tell us how many bytes we have to skip in memory to move to the next position along a certain axis. For example, we have to skip 4 bytes (1 value) to move to the next column, but 20 bytes (5 values) to get to the same position in the next row. As such, the strides for the array x will be (20, 4). Examples >>> y = np.reshape(np.arange(2*3*4), (2,3,4))
>>> y
array([[[ 0,  1,  2,  3],
        [ 4,  5,  6,  7],
        [ 8,  9, 10, 11]],
       [[12, 13, 14, 15],
        [16, 17, 18, 19],
        [20, 21, 22, 23]]])
>>> y.strides
(48, 16, 4)
>>> y[1,1,1]
17
>>> offset=sum(y.strides * np.array((1,1,1)))
>>> offset/y.itemsize
17
 >>> x = np.reshape(np.arange(5*6*7*8), (5,6,7,8)).transpose(2,3,1,0)
>>> x.strides
(32, 4, 224, 1344)
>>> i = np.array([3,5,2,2])
>>> offset = sum(i * x.strides)
>>> x[3,5,2,2]
813
>>> offset / x.itemsize
813


numpy.ma.MaskedArray.sum method   ma.MaskedArray.sum(axis=None, dtype=None, out=None, keepdims=<no value>)[source]

Return the sum of the array elements over the given axis. Masked elements are set to 0 internally. Refer to numpy.sum for full documentation.  See also  numpy.ndarray.sum

corresponding function for ndarrays  numpy.sum

equivalent function    Examples >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> x
masked_array(
  data=[[1, --, 3],
        [--, 5, --],
        [7, --, 9]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)
>>> x.sum()
25
>>> x.sum(axis=1)
masked_array(data=[4, 5, 16],
             mask=[False, False, False],
       fill_value=999999)
>>> x.sum(axis=0)
masked_array(data=[8, 5, 12],
             mask=[False, False, False],
       fill_value=999999)
>>> print(type(x.sum(axis=0, dtype=np.int64)[0]))
<class 'numpy.int64'>


numpy.ma.MaskedArray.swapaxes method   ma.MaskedArray.swapaxes(axis1, axis2)[source]

Return a view of the array with axis1 and axis2 interchanged. Refer to numpy.swapaxes for full documentation.  See also  numpy.swapaxes

equivalent function


numpy.ma.MaskedArray.take method   ma.MaskedArray.take(indices, axis=None, out=None, mode='raise')[source]


numpy.ma.MaskedArray.tobytes method   ma.MaskedArray.tobytes(fill_value=None, order='C')[source]

Return the array data as a string containing the raw bytes in the array. The array is filled with a fill value before the string conversion.  New in version 1.9.0.   Parameters

fill_valuescalar, optional

Value used to fill in the masked values. Default is None, in which case MaskedArray.fill_value is used.
order{‘C’,’F’,’A’}, optional

Order of the data item in the copy. Default is ‘C’.  ‘C’ – C order (row major). ‘F’ – Fortran order (column major). ‘A’ – Any, current order of array. None – Same as ‘A’.       See also  numpy.ndarray.tobytes

tolist, tofile

  Notes As for ndarray.tobytes, information about the shape, dtype, etc., but also about fill_value, will be lost. Examples >>> x = np.ma.array(np.array([[1, 2], [3, 4]]), mask=[[0, 1], [1, 0]])
>>> x.tobytes()
b'\x01\x00\x00\x00\x00\x00\x00\x00?B\x0f\x00\x00\x00\x00\x00?B\x0f\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00'


numpy.ma.MaskedArray.tofile method   ma.MaskedArray.tofile(fid, sep='', format='%s')[source]

Save a masked array to a file in binary format.  Warning This function is not implemented yet.   Raises
 NotImplementedError

When tofile is called.


numpy.ma.MaskedArray.toflex method   ma.MaskedArray.toflex()[source]

Transforms a masked array into a flexible-type array. The flexible type array that is returned will have two fields:  the _data field stores the _data part of the array. the _mask field stores the _mask part of the array.   Parameters
 None
  Returns

recordndarray

A new flexible-type ndarray with two fields: the first element containing a value, the second element containing the corresponding mask boolean. The returned record shape matches self.shape.     Notes A side-effect of transforming a masked array into a flexible ndarray is that meta information (fill_value, …) will be lost. Examples >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> x
masked_array(
  data=[[1, --, 3],
        [--, 5, --],
        [7, --, 9]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)
>>> x.toflex()
array([[(1, False), (2,  True), (3, False)],
       [(4,  True), (5, False), (6,  True)],
       [(7, False), (8,  True), (9, False)]],
      dtype=[('_data', '<i8'), ('_mask', '?')])


numpy.ma.MaskedArray.tolist method   ma.MaskedArray.tolist(fill_value=None)[source]

Return the data portion of the masked array as a hierarchical Python list. Data items are converted to the nearest compatible Python type. Masked values are converted to fill_value. If fill_value is None, the corresponding entries in the output list will be None.  Parameters

fill_valuescalar, optional

The value to use for invalid entries. Default is None.    Returns

resultlist

The Python list representation of the masked array.     Examples >>> x = np.ma.array([[1,2,3], [4,5,6], [7,8,9]], mask=[0] + [1,0]*4)
>>> x.tolist()
[[1, None, 3], [None, 5, None], [7, None, 9]]
>>> x.tolist(-999)
[[1, -999, 3], [-999, 5, -999], [7, -999, 9]]


numpy.ma.MaskedArray.torecords method   ma.MaskedArray.torecords()[source]

Transforms a masked array into a flexible-type array. The flexible type array that is returned will have two fields:  the _data field stores the _data part of the array. the _mask field stores the _mask part of the array.   Parameters
 None
  Returns

recordndarray

A new flexible-type ndarray with two fields: the first element containing a value, the second element containing the corresponding mask boolean. The returned record shape matches self.shape.     Notes A side-effect of transforming a masked array into a flexible ndarray is that meta information (fill_value, …) will be lost. Examples >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> x
masked_array(
  data=[[1, --, 3],
        [--, 5, --],
        [7, --, 9]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)
>>> x.toflex()
array([[(1, False), (2,  True), (3, False)],
       [(4,  True), (5, False), (6,  True)],
       [(7, False), (8,  True), (9, False)]],
      dtype=[('_data', '<i8'), ('_mask', '?')])


numpy.ma.MaskedArray.tostring method   ma.MaskedArray.tostring(fill_value=None, order='C')[source]

A compatibility alias for tobytes, with exactly the same behavior. Despite its name, it returns bytes not strs.  Deprecated since version 1.19.0.


numpy.ma.MaskedArray.trace method   ma.MaskedArray.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


numpy.ma.MaskedArray.transpose method   ma.MaskedArray.transpose(*axes)[source]

Returns a view of the array with axes transposed. For a 1-D array this has no effect, as a transposed vector is simply the same vector. To convert a 1-D array into a 2D column vector, an additional dimension must be added. np.atleast2d(a).T achieves this, as does a[:, np.newaxis]. For a 2-D array, this is a standard matrix transpose. For an n-D array, if axes are given, their order indicates how the axes are permuted (see Examples). If axes are not provided and a.shape = (i[0], i[1], ... i[n-2], i[n-1]), then a.transpose().shape = (i[n-1], i[n-2], ... i[1], i[0]).  Parameters

axesNone, tuple of ints, or n ints

 None or no argument: reverses the order of the axes. tuple of ints: i in the j-th place in the tuple means a’s i-th axis becomes a.transpose()’s j-th axis.
n ints: same as an n-tuple of the same ints (this form is intended simply as a “convenience” alternative to the tuple form)     Returns

outndarray

View of a, with axes suitably permuted.      See also  transpose

Equivalent function  ndarray.T

Array property returning the array transposed.  ndarray.reshape

Give a new shape to an array without changing its data.    Examples >>> a = np.array([[1, 2], [3, 4]])
>>> a
array([[1, 2],
       [3, 4]])
>>> a.transpose()
array([[1, 3],
       [2, 4]])
>>> a.transpose((1, 0))
array([[1, 3],
       [2, 4]])
>>> a.transpose(1, 0)
array([[1, 3],
       [2, 4]])


numpy.ma.MaskedArray.unshare_mask method   ma.MaskedArray.unshare_mask()[source]

Copy the mask and set the sharedmask flag to False. Whether the mask is shared between masked arrays can be seen from the sharedmask property. unshare_mask ensures the mask is not shared. A copy of the mask is only made if it was shared.  See also  sharedmask


numpy.ma.MaskedArray.var method   ma.MaskedArray.var(axis=None, dtype=None, out=None, ddof=0, keepdims=<no value>)[source]

Compute the variance along the specified axis. Returns the variance of the array elements, a measure of the spread of a distribution. The variance is computed for the flattened array by default, otherwise over the specified axis.  Parameters

aarray_like

Array containing numbers whose variance is desired. If a is not an array, a conversion is attempted.
axisNone or int or tuple of ints, optional

Axis or axes along which the variance is computed. The default is to compute the variance of the flattened array.  New in version 1.7.0.  If this is a tuple of ints, a variance is performed over multiple axes, instead of a single axis or all the axes as before.
dtypedata-type, optional

Type to use in computing the variance. For arrays of integer type the default is float64; for arrays of float types it is the same as the array type.
outndarray, optional

Alternate output array in which to place the result. It must have the same shape as the expected output, but the type is cast if necessary.
ddofint, optional

“Delta Degrees of Freedom”: the divisor used in the calculation is N - ddof, where N represents the number of elements. By default ddof is zero.
keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. If the default value is passed, then keepdims will not be passed through to the var method of sub-classes of ndarray, however any non-default value will be. If the sub-class’ method does not implement keepdims any exceptions will be raised.
wherearray_like of bool, optional

Elements to include in the variance. See reduce for details.  New in version 1.20.0.     Returns

variancendarray, see dtype parameter above

If out=None, returns a new array containing the variance; otherwise, a reference to the output array is returned.      See also
std, mean, nanmean, nanstd, nanvar

Output type determination
  Notes The variance is the average of the squared deviations from the mean, i.e., var = mean(x), where x = abs(a - a.mean())**2. The mean is typically calculated as x.sum() / N, where N = len(x). If, however, ddof is specified, the divisor N - ddof is used instead. In standard statistical practice, ddof=1 provides an unbiased estimator of the variance of a hypothetical infinite population. ddof=0 provides a maximum likelihood estimate of the variance for normally distributed variables. Note that for complex numbers, the absolute value is taken before squaring, so that the result is always real and nonnegative. For floating-point input, the variance is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32 (see example below). Specifying a higher-accuracy accumulator using the dtype keyword can alleviate this issue. Examples >>> a = np.array([[1, 2], [3, 4]])
>>> np.var(a)
1.25
>>> np.var(a, axis=0)
array([1.,  1.])
>>> np.var(a, axis=1)
array([0.25,  0.25])
 In single precision, var() can be inaccurate: >>> a = np.zeros((2, 512*512), dtype=np.float32)
>>> a[0, :] = 1.0
>>> a[1, :] = 0.1
>>> np.var(a)
0.20250003
 Computing the variance in float64 is more accurate: >>> np.var(a, dtype=np.float64)
0.20249999932944759 # may vary
>>> ((1-0.55)**2 + (0.1-0.55)**2)/2
0.2025
 Specifying a where argument: >>> a = np.array([[14, 8, 11, 10], [7, 9, 10, 11], [10, 15, 5, 10]])
>>> np.var(a)
6.833333333333333 # may vary
>>> np.var(a, where=[[True], [True], [False]])
4.0


numpy.ma.MaskedArray.view method   ma.MaskedArray.view(dtype=None, type=None, fill_value=None)[source]

Return a view of the MaskedArray data.  Parameters

dtypedata-type or ndarray sub-class, optional

Data-type descriptor of the returned view, e.g., float32 or int16. The default, None, results in the view having the same data-type as a. As with ndarray.view, dtype can also be specified as an ndarray sub-class, which then specifies the type of the returned object (this is equivalent to setting the type parameter).
typePython type, optional

Type of the returned view, either ndarray or a subclass. The default None results in type preservation.
fill_valuescalar, optional

The value to use for invalid entries (None by default). If None, then this argument is inferred from the passed dtype, or in its absence the original array, as discussed in the notes below.      See also  numpy.ndarray.view

Equivalent method on ndarray object.    Notes a.view() is used two different ways: a.view(some_dtype) or a.view(dtype=some_dtype) constructs a view of the array’s memory with a different data-type. This can cause a reinterpretation of the bytes of memory. a.view(ndarray_subclass) or a.view(type=ndarray_subclass) just returns an instance of ndarray_subclass that looks at the same array (same shape, dtype, etc.) This does not cause a reinterpretation of the memory. If fill_value is not specified, but dtype is specified (and is not an ndarray sub-class), the fill_value of the MaskedArray will be reset. If neither fill_value nor dtype are specified (or if dtype is an ndarray sub-class), then the fill value is preserved. Finally, if fill_value is specified, but dtype is not, the fill value is set to the specified value. For a.view(some_dtype), if some_dtype has a different number of bytes per entry than the previous dtype (for example, converting a regular array to a structured array), then the behavior of the view cannot be predicted just from the superficial appearance of a (shown by print(a)). It also depends on exactly how a is stored in memory. Therefore if a is C-ordered versus fortran-ordered, versus defined as a slice or transpose, etc., the view may give different results.


numpy.ma.max   ma.max(obj, axis=None, out=None, fill_value=None, keepdims=<no value>)[source]

Return the maximum along a given axis.  Parameters

axis{None, int}, optional

Axis along which to operate. By default, axis is None and the flattened input is used.
outarray_like, optional

Alternative output array in which to place the result. Must be of the same shape and buffer length as the expected output.
fill_valuescalar or None, optional

Value used to fill in the masked values. If None, use the output of maximum_fill_value().
keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the array.    Returns

amaxarray_like

New array holding the result. If out was specified, out is returned.      See also  ma.maximum_fill_value

Returns the maximum filling value for a given datatype.


numpy.ma.maximum_fill_value   ma.maximum_fill_value(obj)[source]

Return the minimum value that can be represented by the dtype of an object. This function is useful for calculating a fill value suitable for taking the maximum of an array with a given dtype.  Parameters

objndarray, dtype or scalar

An object that can be queried for it’s numeric type.    Returns

valscalar

The minimum representable value.    Raises
 TypeError

If obj isn’t a suitable numeric type.      See also  minimum_fill_value

The inverse function.  set_fill_value

Set the filling value of a masked array.  MaskedArray.fill_value

Return current fill value.    Examples >>> import numpy.ma as ma
>>> a = np.int8()
>>> ma.maximum_fill_value(a)
-128
>>> a = np.int32()
>>> ma.maximum_fill_value(a)
-2147483648
 An array of numeric data can also be passed. >>> a = np.array([1, 2, 3], dtype=np.int8)
>>> ma.maximum_fill_value(a)
-128
>>> a = np.array([1, 2, 3], dtype=np.float32)
>>> ma.maximum_fill_value(a)
-inf


numpy.ma.mean   ma.mean(self, axis=None, dtype=None, out=None, keepdims=<no value>) = <numpy.ma.core._frommethod object>

Returns the average of the array elements along given axis. Masked entries are ignored, and result elements which are not finite will be masked. Refer to numpy.mean for full documentation.  See also  numpy.ndarray.mean

corresponding function for ndarrays  numpy.mean

Equivalent function  numpy.ma.average

Weighted average.    Examples >>> a = np.ma.array([1,2,3], mask=[False, False, True])
>>> a
masked_array(data=[1, 2, --],
             mask=[False, False,  True],
       fill_value=999999)
>>> a.mean()
1.5


numpy.ma.median   ma.median(a, axis=None, out=None, overwrite_input=False, keepdims=False)[source]

Compute the median along the specified axis. Returns the median of the array elements.  Parameters

aarray_like

Input array or object that can be converted to an array.
axisint, optional

Axis along which the medians are computed. The default (None) is to compute the median along a flattened version of the array.
outndarray, optional

Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary.
overwrite_inputbool, optional

If True, then allow use of memory of input array (a) for calculations. The input array will be modified by the call to median. This will save memory when you do not need to preserve the contents of the input array. Treat the input as undefined, but it will probably be fully or partially sorted. Default is False. Note that, if overwrite_input is True, and the input is not already an ndarray, an error will be raised.
keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.  New in version 1.10.0.     Returns

medianndarray

A new array holding the result is returned unless out is specified, in which case a reference to out is returned. Return data-type is float64 for integers and floats smaller than float64, or the input data-type, otherwise.      See also  mean
  Notes Given a vector V with N non masked values, the median of V is the middle value of a sorted copy of V (Vs) - i.e. Vs[(N-1)/2], when N is odd, or {Vs[N/2 - 1] + Vs[N/2]}/2 when N is even. Examples >>> x = np.ma.array(np.arange(8), mask=[0]*4 + [1]*4)
>>> np.ma.median(x)
1.5
 >>> x = np.ma.array(np.arange(10).reshape(2, 5), mask=[0]*6 + [1]*4)
>>> np.ma.median(x)
2.5
>>> np.ma.median(x, axis=-1, overwrite_input=True)
masked_array(data=[2.0, 5.0],
             mask=[False, False],
       fill_value=1e+20)


numpy.ma.min   ma.min(obj, axis=None, out=None, fill_value=None, keepdims=<no value>)[source]

Return the minimum along a given axis.  Parameters

axis{None, int}, optional

Axis along which to operate. By default, axis is None and the flattened input is used.
outarray_like, optional

Alternative output array in which to place the result. Must be of the same shape and buffer length as the expected output.
fill_valuescalar or None, optional

Value used to fill in the masked values. If None, use the output of minimum_fill_value.
keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the array.    Returns

aminarray_like

New array holding the result. If out was specified, out is returned.      See also  ma.minimum_fill_value

Returns the minimum filling value for a given datatype.


numpy.ma.minimum_fill_value   ma.minimum_fill_value(obj)[source]

Return the maximum value that can be represented by the dtype of an object. This function is useful for calculating a fill value suitable for taking the minimum of an array with a given dtype.  Parameters

objndarray, dtype or scalar

An object that can be queried for it’s numeric type.    Returns

valscalar

The maximum representable value.    Raises
 TypeError

If obj isn’t a suitable numeric type.      See also  maximum_fill_value

The inverse function.  set_fill_value

Set the filling value of a masked array.  MaskedArray.fill_value

Return current fill value.    Examples >>> import numpy.ma as ma
>>> a = np.int8()
>>> ma.minimum_fill_value(a)
127
>>> a = np.int32()
>>> ma.minimum_fill_value(a)
2147483647
 An array of numeric data can also be passed. >>> a = np.array([1, 2, 3], dtype=np.int8)
>>> ma.minimum_fill_value(a)
127
>>> a = np.array([1, 2, 3], dtype=np.float32)
>>> ma.minimum_fill_value(a)
inf


numpy.ma.mr_   ma.mr_ = <numpy.ma.extras.mr_class object>

Translate slice objects to concatenation along the first axis. This is the masked array version of lib.index_tricks.RClass.  See also  lib.index_tricks.RClass
  Examples >>> np.ma.mr_[np.ma.array([1,2,3]), 0, 0, np.ma.array([4,5,6])]
masked_array(data=[1, 2, 3, ..., 4, 5, 6],
             mask=False,
       fill_value=999999)


numpy.ma.nonzero   ma.nonzero(self) = <numpy.ma.core._frommethod object>

Return the indices of unmasked elements that are not zero. Returns a tuple of arrays, one for each dimension, containing the indices of the non-zero elements in that dimension. The corresponding non-zero values can be obtained with: a[a.nonzero()]
 To group the indices by element, rather than dimension, use instead: np.transpose(a.nonzero())
 The result of this is always a 2d array, with a row for each non-zero element.  Parameters
 None
  Returns

tuple_of_arraystuple

Indices of elements that are non-zero.      See also  numpy.nonzero

Function operating on ndarrays.  flatnonzero

Return indices that are non-zero in the flattened version of the input array.  numpy.ndarray.nonzero

Equivalent ndarray method.  count_nonzero

Counts the number of non-zero elements in the input array.    Examples >>> import numpy.ma as ma
>>> x = ma.array(np.eye(3))
>>> x
masked_array(
  data=[[1., 0., 0.],
        [0., 1., 0.],
        [0., 0., 1.]],
  mask=False,
  fill_value=1e+20)
>>> x.nonzero()
(array([0, 1, 2]), array([0, 1, 2]))
 Masked elements are ignored. >>> x[1, 1] = ma.masked
>>> x
masked_array(
  data=[[1.0, 0.0, 0.0],
        [0.0, --, 0.0],
        [0.0, 0.0, 1.0]],
  mask=[[False, False, False],
        [False,  True, False],
        [False, False, False]],
  fill_value=1e+20)
>>> x.nonzero()
(array([0, 2]), array([0, 2]))
 Indices can also be grouped by element. >>> np.transpose(x.nonzero())
array([[0, 0],
       [2, 2]])
 A common use for nonzero is to find the indices of an array, where a condition is True. Given an array a, the condition a > 3 is a boolean array and since False is interpreted as 0, ma.nonzero(a > 3) yields the indices of the a where the condition is true. >>> a = ma.array([[1,2,3],[4,5,6],[7,8,9]])
>>> a > 3
masked_array(
  data=[[False, False, False],
        [ True,  True,  True],
        [ True,  True,  True]],
  mask=False,
  fill_value=True)
>>> ma.nonzero(a > 3)
(array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2]))
 The nonzero method of the condition array can also be called. >>> (a > 3).nonzero()
(array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2]))


numpy.ma.notmasked_contiguous   ma.notmasked_contiguous(a, axis=None)[source]

Find contiguous unmasked data in a masked array along the given axis.  Parameters

aarray_like

The input array.
axisint, optional

Axis along which to perform the operation. If None (default), applies to a flattened version of the array, and this is the same as flatnotmasked_contiguous.    Returns

endpointslist

A list of slices (start and end indexes) of unmasked indexes in the array. If the input is 2d and axis is specified, the result is a list of lists.      See also
flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges

clump_masked, clump_unmasked

  Notes Only accepts 2-D arrays at most. Examples >>> a = np.arange(12).reshape((3, 4))
>>> mask = np.zeros_like(a)
>>> mask[1:, :-1] = 1; mask[0, 1] = 1; mask[-1, 0] = 0
>>> ma = np.ma.array(a, mask=mask)
>>> ma
masked_array(
  data=[[0, --, 2, 3],
        [--, --, --, 7],
        [8, --, --, 11]],
  mask=[[False,  True, False, False],
        [ True,  True,  True, False],
        [False,  True,  True, False]],
  fill_value=999999)
>>> np.array(ma[~ma.mask])
array([ 0,  2,  3,  7, 8, 11])
 >>> np.ma.notmasked_contiguous(ma)
[slice(0, 1, None), slice(2, 4, None), slice(7, 9, None), slice(11, 12, None)]
 >>> np.ma.notmasked_contiguous(ma, axis=0)
[[slice(0, 1, None), slice(2, 3, None)], [], [slice(0, 1, None)], [slice(0, 3, None)]]
 >>> np.ma.notmasked_contiguous(ma, axis=1)
[[slice(0, 1, None), slice(2, 4, None)], [slice(3, 4, None)], [slice(0, 1, None), slice(3, 4, None)]]


numpy.ma.notmasked_edges   ma.notmasked_edges(a, axis=None)[source]

Find the indices of the first and last unmasked values along an axis. If all values are masked, return None. Otherwise, return a list of two tuples, corresponding to the indices of the first and last unmasked values respectively.  Parameters

aarray_like

The input array.
axisint, optional

Axis along which to perform the operation. If None (default), applies to a flattened version of the array.    Returns

edgesndarray or list

An array of start and end indexes if there are any masked data in the array. If there are no masked data in the array, edges is a list of the first and last index.      See also
flatnotmasked_contiguous, flatnotmasked_edges, notmasked_contiguous

clump_masked, clump_unmasked

  Examples >>> a = np.arange(9).reshape((3, 3))
>>> m = np.zeros_like(a)
>>> m[1:, 1:] = 1
 >>> am = np.ma.array(a, mask=m)
>>> np.array(am[~am.mask])
array([0, 1, 2, 3, 6])
 >>> np.ma.notmasked_edges(am)
array([0, 6])


numpy.ma.ones   ma.ones(shape, dtype=None, order='C') = <numpy.ma.core._convert2ma object>

Return a new array of given shape and type, filled with ones.  Parameters

shapeint or sequence of ints

Shape of the new array, e.g., (2, 3) or 2.
dtypedata-type, optional

The desired 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 ones with the given shape, dtype, and order.      See also  ones_like

Return an array of ones with shape and type of input.  empty

Return a new uninitialized array.  zeros

Return a new array setting values to zero.  full

Return a new array of given shape filled with value.    Examples >>> np.ones(5)
array([1., 1., 1., 1., 1.])
 >>> np.ones((5,), dtype=int)
array([1, 1, 1, 1, 1])
 >>> np.ones((2, 1))
array([[1.],
       [1.]])
 >>> s = (2,2)
>>> np.ones(s)
array([[1.,  1.],
       [1.,  1.]])


numpy.ma.ones_like   ma.ones_like(*args, **kwargs) = <numpy.ma.core._convert2ma object>

Return an array of ones with the same shape and type as a given array.  Parameters

aarray_like

The shape and data-type of a 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 a is Fortran contiguous, ‘C’ otherwise. ‘K’ means match the layout of a 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 a, 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 ones with the same shape and type as a.      See also  empty_like

Return an empty array 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.  ones

Return a new array setting values to one.    Examples >>> x = np.arange(6)
>>> x = x.reshape((2, 3))
>>> x
array([[0, 1, 2],
       [3, 4, 5]])
>>> np.ones_like(x)
array([[1, 1, 1],
       [1, 1, 1]])
 >>> y = np.arange(3, dtype=float)
>>> y
array([0., 1., 2.])
>>> np.ones_like(y)
array([1.,  1.,  1.])


numpy.ma.outer   ma.outer(a, b)[source]

Compute the outer product of two vectors. Given two vectors, a = [a0, a1, ..., aM] and b = [b0, b1, ..., bN], the outer product [1] is: [[a0*b0  a0*b1 ... a0*bN ]
 [a1*b0    .
 [ ...          .
 [aM*b0            aM*bN ]]
  Parameters

a(M,) array_like

First input vector. Input is flattened if not already 1-dimensional.
b(N,) array_like

Second input vector. Input is flattened if not already 1-dimensional.
out(M, N) ndarray, optional

A location where the result is stored  New in version 1.9.0.     Returns

out(M, N) ndarray

out[i, j] = a[i] * b[j]      See also  inner
einsum

einsum('i,j->ij', a.ravel(), b.ravel()) is the equivalent.  ufunc.outer

A generalization to dimensions other than 1D and other operations. np.multiply.outer(a.ravel(), b.ravel()) is the equivalent.  tensordot

np.tensordot(a.ravel(), b.ravel(), axes=((), ())) is the equivalent.    Notes Masked values are replaced by 0. References  1
: G. H. Golub and C. F. Van Loan, Matrix Computations, 3rd ed., Baltimore, MD, Johns Hopkins University Press, 1996, pg. 8.   Examples Make a (very coarse) grid for computing a Mandelbrot set: >>> rl = np.outer(np.ones((5,)), np.linspace(-2, 2, 5))
>>> rl
array([[-2., -1.,  0.,  1.,  2.],
       [-2., -1.,  0.,  1.,  2.],
       [-2., -1.,  0.,  1.,  2.],
       [-2., -1.,  0.,  1.,  2.],
       [-2., -1.,  0.,  1.,  2.]])
>>> im = np.outer(1j*np.linspace(2, -2, 5), np.ones((5,)))
>>> im
array([[0.+2.j, 0.+2.j, 0.+2.j, 0.+2.j, 0.+2.j],
       [0.+1.j, 0.+1.j, 0.+1.j, 0.+1.j, 0.+1.j],
       [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
       [0.-1.j, 0.-1.j, 0.-1.j, 0.-1.j, 0.-1.j],
       [0.-2.j, 0.-2.j, 0.-2.j, 0.-2.j, 0.-2.j]])
>>> grid = rl + im
>>> grid
array([[-2.+2.j, -1.+2.j,  0.+2.j,  1.+2.j,  2.+2.j],
       [-2.+1.j, -1.+1.j,  0.+1.j,  1.+1.j,  2.+1.j],
       [-2.+0.j, -1.+0.j,  0.+0.j,  1.+0.j,  2.+0.j],
       [-2.-1.j, -1.-1.j,  0.-1.j,  1.-1.j,  2.-1.j],
       [-2.-2.j, -1.-2.j,  0.-2.j,  1.-2.j,  2.-2.j]])
 An example using a “vector” of letters: >>> x = np.array(['a', 'b', 'c'], dtype=object)
>>> np.outer(x, [1, 2, 3])
array([['a', 'aa', 'aaa'],
       ['b', 'bb', 'bbb'],
       ['c', 'cc', 'ccc']], dtype=object)


numpy.ma.outerproduct   ma.outerproduct(a, b)[source]

Compute the outer product of two vectors. Given two vectors, a = [a0, a1, ..., aM] and b = [b0, b1, ..., bN], the outer product [1] is: [[a0*b0  a0*b1 ... a0*bN ]
 [a1*b0    .
 [ ...          .
 [aM*b0            aM*bN ]]
  Parameters

a(M,) array_like

First input vector. Input is flattened if not already 1-dimensional.
b(N,) array_like

Second input vector. Input is flattened if not already 1-dimensional.
out(M, N) ndarray, optional

A location where the result is stored  New in version 1.9.0.     Returns

out(M, N) ndarray

out[i, j] = a[i] * b[j]      See also  inner
einsum

einsum('i,j->ij', a.ravel(), b.ravel()) is the equivalent.  ufunc.outer

A generalization to dimensions other than 1D and other operations. np.multiply.outer(a.ravel(), b.ravel()) is the equivalent.  tensordot

np.tensordot(a.ravel(), b.ravel(), axes=((), ())) is the equivalent.    Notes Masked values are replaced by 0. References  1
: G. H. Golub and C. F. Van Loan, Matrix Computations, 3rd ed., Baltimore, MD, Johns Hopkins University Press, 1996, pg. 8.   Examples Make a (very coarse) grid for computing a Mandelbrot set: >>> rl = np.outer(np.ones((5,)), np.linspace(-2, 2, 5))
>>> rl
array([[-2., -1.,  0.,  1.,  2.],
       [-2., -1.,  0.,  1.,  2.],
       [-2., -1.,  0.,  1.,  2.],
       [-2., -1.,  0.,  1.,  2.],
       [-2., -1.,  0.,  1.,  2.]])
>>> im = np.outer(1j*np.linspace(2, -2, 5), np.ones((5,)))
>>> im
array([[0.+2.j, 0.+2.j, 0.+2.j, 0.+2.j, 0.+2.j],
       [0.+1.j, 0.+1.j, 0.+1.j, 0.+1.j, 0.+1.j],
       [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
       [0.-1.j, 0.-1.j, 0.-1.j, 0.-1.j, 0.-1.j],
       [0.-2.j, 0.-2.j, 0.-2.j, 0.-2.j, 0.-2.j]])
>>> grid = rl + im
>>> grid
array([[-2.+2.j, -1.+2.j,  0.+2.j,  1.+2.j,  2.+2.j],
       [-2.+1.j, -1.+1.j,  0.+1.j,  1.+1.j,  2.+1.j],
       [-2.+0.j, -1.+0.j,  0.+0.j,  1.+0.j,  2.+0.j],
       [-2.-1.j, -1.-1.j,  0.-1.j,  1.-1.j,  2.-1.j],
       [-2.-2.j, -1.-2.j,  0.-2.j,  1.-2.j,  2.-2.j]])
 An example using a “vector” of letters: >>> x = np.array(['a', 'b', 'c'], dtype=object)
>>> np.outer(x, [1, 2, 3])
array([['a', 'aa', 'aaa'],
       ['b', 'bb', 'bbb'],
       ['c', 'cc', 'ccc']], dtype=object)


numpy.ma.polyfit   ma.polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False)[source]

Least squares polynomial fit.  Note This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in numpy.polynomial is preferred. A summary of the differences can be found in the transition guide.  Fit a polynomial p(x) = p[0] * x**deg + ... + p[deg] of degree deg to points (x, y). Returns a vector of coefficients p that minimises the squared error in the order deg, deg-1, … 0. The Polynomial.fit class method is recommended for new code as it is more stable numerically. See the documentation of the method for more information.  Parameters

xarray_like, shape (M,)

x-coordinates of the M sample points (x[i], y[i]).
yarray_like, shape (M,) or (M, K)

y-coordinates of the sample points. Several data sets of sample points sharing the same x-coordinates can be fitted at once by passing in a 2D-array that contains one dataset per column.
degint

Degree of the fitting polynomial
rcondfloat, optional

Relative condition number of the fit. Singular values smaller than this relative to the largest singular value will be ignored. The default value is len(x)*eps, where eps is the relative precision of the float type, about 2e-16 in most cases.
fullbool, optional

Switch determining nature of return value. When it is False (the default) just the coefficients are returned, when True diagnostic information from the singular value decomposition is also returned.
warray_like, shape (M,), optional

Weights. If not None, the weight w[i] applies to the unsquared residual y[i] - y_hat[i] at x[i]. Ideally the weights are chosen so that the errors of the products w[i]*y[i] all have the same variance. When using inverse-variance weighting, use w[i] = 1/sigma(y[i]). The default value is None.
covbool or str, optional

If given and not False, return not just the estimate but also its covariance matrix. By default, the covariance are scaled by chi2/dof, where dof = M - (deg + 1), i.e., the weights are presumed to be unreliable except in a relative sense and everything is scaled such that the reduced chi2 is unity. This scaling is omitted if cov='unscaled', as is relevant for the case that the weights are w = 1/sigma, with sigma known to be a reliable estimate of the uncertainty.    Returns

pndarray, shape (deg + 1,) or (deg + 1, K)

Polynomial coefficients, highest power first. If y was 2-D, the coefficients for k-th data set are in p[:,k].  residuals, rank, singular_values, rcond

These values are only returned if full == True  residuals – sum of squared residuals of the least squares fit
 rank – the effective rank of the scaled Vandermonde

coefficient matrix
 singular_values – singular values of the scaled Vandermonde

coefficient matrix    rcond – value of rcond.  For more details, see numpy.linalg.lstsq.
Vndarray, shape (M,M) or (M,M,K)

Present only if full == False and cov == True. The covariance matrix of the polynomial coefficient estimates. The diagonal of this matrix are the variance estimates for each coefficient. If y is a 2-D array, then the covariance matrix for the k-th data set are in V[:,:,k]    Warns
 RankWarning

The rank of the coefficient matrix in the least-squares fit is deficient. The warning is only raised if full == False. The warnings can be turned off by >>> import warnings
>>> warnings.simplefilter('ignore', np.RankWarning)
      See also  polyval

Compute polynomial values.  linalg.lstsq

Computes a least-squares fit.  scipy.interpolate.UnivariateSpline

Computes spline fits.    Notes Any masked values in x is propagated in y, and vice-versa. The solution minimizes the squared error  \[E = \sum_{j=0}^k |p(x_j) - y_j|^2\] in the equations: x[0]**n * p[0] + ... + x[0] * p[n-1] + p[n] = y[0]
x[1]**n * p[0] + ... + x[1] * p[n-1] + p[n] = y[1]
...
x[k]**n * p[0] + ... + x[k] * p[n-1] + p[n] = y[k]
 The coefficient matrix of the coefficients p is a Vandermonde matrix. polyfit issues a RankWarning when the least-squares fit is badly conditioned. This implies that the best fit is not well-defined due to numerical error. The results may be improved by lowering the polynomial degree or by replacing x by x - x.mean(). The rcond parameter can also be set to a value smaller than its default, but the resulting fit may be spurious: including contributions from the small singular values can add numerical noise to the result. Note that fitting polynomial coefficients is inherently badly conditioned when the degree of the polynomial is large or the interval of sample points is badly centered. The quality of the fit should always be checked in these cases. When polynomial fits are not satisfactory, splines may be a good alternative. References  1
Wikipedia, “Curve fitting”, https://en.wikipedia.org/wiki/Curve_fitting  2
Wikipedia, “Polynomial interpolation”, https://en.wikipedia.org/wiki/Polynomial_interpolation   Examples >>> import warnings
>>> x = np.array([0.0, 1.0, 2.0, 3.0,  4.0,  5.0])
>>> y = np.array([0.0, 0.8, 0.9, 0.1, -0.8, -1.0])
>>> z = np.polyfit(x, y, 3)
>>> z
array([ 0.08703704, -0.81349206,  1.69312169, -0.03968254]) # may vary
 It is convenient to use poly1d objects for dealing with polynomials: >>> p = np.poly1d(z)
>>> p(0.5)
0.6143849206349179 # may vary
>>> p(3.5)
-0.34732142857143039 # may vary
>>> p(10)
22.579365079365115 # may vary
 High-order polynomials may oscillate wildly: >>> with warnings.catch_warnings():
...     warnings.simplefilter('ignore', np.RankWarning)
...     p30 = np.poly1d(np.polyfit(x, y, 30))
...
>>> p30(4)
-0.80000000000000204 # may vary
>>> p30(5)
-0.99999999999999445 # may vary
>>> p30(4.5)
-0.10547061179440398 # may vary
 Illustration: >>> import matplotlib.pyplot as plt
>>> xp = np.linspace(-2, 6, 100)
>>> _ = plt.plot(x, y, '.', xp, p(xp), '-', xp, p30(xp), '--')
>>> plt.ylim(-2,2)
(-2, 2)
>>> plt.show()


numpy.ma.power   ma.power(a, b, third=None)[source]

Returns element-wise base array raised to power from second array. This is the masked array version of numpy.power. For details see numpy.power.  See also  numpy.power
  Notes The out argument to numpy.power is not supported, third has to be None.


numpy.ma.prod   ma.prod(self, axis=None, dtype=None, out=None, keepdims=<no value>) = <numpy.ma.core._frommethod object>

Return the product of the array elements over the given axis. Masked elements are set to 1 internally for computation. Refer to numpy.prod for full documentation.  See also  numpy.ndarray.prod

corresponding function for ndarrays  numpy.prod

equivalent function    Notes Arithmetic is modular when using integer types, and no error is raised on overflow.


numpy.ma.ptp   ma.ptp(obj, axis=None, out=None, fill_value=None, keepdims=<no value>)[source]

Return (maximum - minimum) along the given dimension (i.e. peak-to-peak value).  Warning ptp preserves the data type of the array. This means the return value for an input of signed integers with n bits (e.g. np.int8, np.int16, etc) is also a signed integer with n bits. In that case, peak-to-peak values greater than 2**(n-1)-1 will be returned as negative values. An example with a work-around is shown below.   Parameters

axis{None, int}, optional

Axis along which to find the peaks. If None (default) the flattened array is used.
out{None, array_like}, optional

Alternative output array in which to place the result. It must have the same shape and buffer length as the expected output but the type will be cast if necessary.
fill_valuescalar or None, optional

Value used to fill in the masked values.
keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the array.    Returns

ptpndarray.

A new array holding the result, unless out was specified, in which case a reference to out is returned.     Examples >>> x = np.ma.MaskedArray([[4, 9, 2, 10],
...                        [6, 9, 7, 12]])
 >>> x.ptp(axis=1)
masked_array(data=[8, 6],
             mask=False,
       fill_value=999999)
 >>> x.ptp(axis=0)
masked_array(data=[2, 0, 5, 2],
             mask=False,
       fill_value=999999)
 >>> x.ptp()
10
 This example shows that a negative value can be returned when the input is an array of signed integers. >>> y = np.ma.MaskedArray([[1, 127],
...                        [0, 127],
...                        [-1, 127],
...                        [-2, 127]], dtype=np.int8)
>>> y.ptp(axis=1)
masked_array(data=[ 126,  127, -128, -127],
             mask=False,
       fill_value=999999,
            dtype=int8)
 A work-around is to use the view() method to view the result as unsigned integers with the same bit width: >>> y.ptp(axis=1).view(np.uint8)
masked_array(data=[126, 127, 128, 129],
             mask=False,
       fill_value=999999,
            dtype=uint8)


numpy.ma.ravel   ma.ravel(self, order='C') = <numpy.ma.core._frommethod object>

Returns a 1D version of self, as a view.  Parameters

order{‘C’, ‘F’, ‘A’, ‘K’}, optional

The elements of a are read using this index order. ‘C’ means to index the elements in C-like order, with the last axis index changing fastest, back to the first axis index changing slowest. ‘F’ means to index the elements in Fortran-like index order, with the first index changing fastest, and the last index changing slowest. Note that the ‘C’ and ‘F’ options take no account of the memory layout of the underlying array, and only refer to the order of axis indexing. ‘A’ means to read the elements in Fortran-like index order if m is Fortran contiguous in memory, C-like order otherwise. ‘K’ means to read the elements in the order they occur in memory, except for reversing the data when strides are negative. By default, ‘C’ index order is used.    Returns
 MaskedArray

Output view is of shape (self.size,) (or (np.ma.product(self.shape),)).     Examples >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> x
masked_array(
  data=[[1, --, 3],
        [--, 5, --],
        [7, --, 9]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)
>>> x.ravel()
masked_array(data=[1, --, 3, --, 5, --, 7, --, 9],
             mask=[False,  True, False,  True, False,  True, False,  True,
                   False],
       fill_value=999999)


numpy.ma.reshape   ma.reshape(a, new_shape, order='C')[source]

Returns an array containing the same data with a new shape. Refer to MaskedArray.reshape for full documentation.  See also  MaskedArray.reshape

equivalent function


numpy.ma.resize   ma.resize(x, new_shape)[source]

Return a new masked array with the specified size and shape. This is the masked equivalent of the numpy.resize function. The new array is filled with repeated copies of x (in the order that the data are stored in memory). If x is masked, the new array will be masked, and the new mask will be a repetition of the old one.  See also  numpy.resize

Equivalent function in the top level NumPy module.    Examples >>> import numpy.ma as ma
>>> a = ma.array([[1, 2] ,[3, 4]])
>>> a[0, 1] = ma.masked
>>> a
masked_array(
  data=[[1, --],
        [3, 4]],
  mask=[[False,  True],
        [False, False]],
  fill_value=999999)
>>> np.resize(a, (3, 3))
masked_array(
  data=[[1, 2, 3],
        [4, 1, 2],
        [3, 4, 1]],
  mask=False,
  fill_value=999999)
>>> ma.resize(a, (3, 3))
masked_array(
  data=[[1, --, 3],
        [4, 1, --],
        [3, 4, 1]],
  mask=[[False,  True, False],
        [False, False,  True],
        [False, False, False]],
  fill_value=999999)
 A MaskedArray is always returned, regardless of the input type. >>> a = np.array([[1, 2] ,[3, 4]])
>>> ma.resize(a, (3, 3))
masked_array(
  data=[[1, 2, 3],
        [4, 1, 2],
        [3, 4, 1]],
  mask=False,
  fill_value=999999)


numpy.ma.round   ma.round(a, decimals=0, out=None)[source]

Return a copy of a, rounded to ‘decimals’ places. When ‘decimals’ is negative, it specifies the number of positions to the left of the decimal point. The real and imaginary parts of complex numbers are rounded separately. Nothing is done if the array is not of float type and ‘decimals’ is greater than or equal to 0.  Parameters

decimalsint

Number of decimals to round to. May be negative.
outarray_like

Existing array to use for output. If not given, returns a default copy of a.     Notes If out is given and does not have a mask attribute, the mask of a is lost!


numpy.ma.row_stack   ma.row_stack(*args, **kwargs) = <numpy.ma.extras._fromnxfunction_seq object>

Stack arrays in sequence vertically (row wise). This is equivalent to concatenation along the first axis after 1-D arrays of shape (N,) have been reshaped to (1,N). Rebuilds arrays divided by vsplit. 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 first axis. 1-D arrays must have the same length.    Returns

stackedndarray

The array formed by stacking the given arrays, will be at least 2-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.  hstack

Stack arrays in sequence horizontally (column wise).  dstack

Stack arrays in sequence depth wise (along third axis).  column_stack

Stack 1-D arrays as columns into a 2-D array.  vsplit

Split an array into multiple sub-arrays vertically (row-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.vstack((a,b))
array([[1, 2, 3],
       [4, 5, 6]])
 >>> a = np.array([[1], [2], [3]])
>>> b = np.array([[4], [5], [6]])
>>> np.vstack((a,b))
array([[1],
       [2],
       [3],
       [4],
       [5],
       [6]])


numpy.ma.set_fill_value   ma.set_fill_value(a, fill_value)[source]

Set the filling value of a, if a is a masked array. This function changes the fill value of the masked array a in place. If a is not a masked array, the function returns silently, without doing anything.  Parameters

aarray_like

Input array.
fill_valuedtype

Filling value. A consistency test is performed to make sure the value is compatible with the dtype of a.    Returns
 None

Nothing returned by this function.      See also  maximum_fill_value

Return the default fill value for a dtype.  MaskedArray.fill_value

Return current fill value.  MaskedArray.set_fill_value

Equivalent method.    Examples >>> import numpy.ma as ma
>>> a = np.arange(5)
>>> a
array([0, 1, 2, 3, 4])
>>> a = ma.masked_where(a < 3, a)
>>> a
masked_array(data=[--, --, --, 3, 4],
             mask=[ True,  True,  True, False, False],
       fill_value=999999)
>>> ma.set_fill_value(a, -999)
>>> a
masked_array(data=[--, --, --, 3, 4],
             mask=[ True,  True,  True, False, False],
       fill_value=-999)
 Nothing happens if a is not a masked array. >>> a = list(range(5))
>>> a
[0, 1, 2, 3, 4]
>>> ma.set_fill_value(a, 100)
>>> a
[0, 1, 2, 3, 4]
>>> a = np.arange(5)
>>> a
array([0, 1, 2, 3, 4])
>>> ma.set_fill_value(a, 100)
>>> a
array([0, 1, 2, 3, 4])


numpy.ma.shape   ma.shape(obj)[source]

Return the shape of an array.  Parameters

aarray_like

Input array.    Returns

shapetuple of ints

The elements of the shape tuple give the lengths of the corresponding array dimensions.      See also  len
ndarray.shape

Equivalent array method.    Examples >>> np.shape(np.eye(3))
(3, 3)
>>> np.shape([[1, 2]])
(1, 2)
>>> np.shape([0])
(1,)
>>> np.shape(0)
()
 >>> a = np.array([(1, 2), (3, 4)], dtype=[('x', 'i4'), ('y', 'i4')])
>>> np.shape(a)
(2,)
>>> a.shape
(2,)


numpy.ma.size   ma.size(obj, axis=None)[source]

Return the number of elements along a given axis.  Parameters

aarray_like

Input data.
axisint, optional

Axis along which the elements are counted. By default, give the total number of elements.    Returns

element_countint

Number of elements along the specified axis.      See also  shape

dimensions of array  ndarray.shape

dimensions of array  ndarray.size

number of elements in array    Examples >>> a = np.array([[1,2,3],[4,5,6]])
>>> np.size(a)
6
>>> np.size(a,1)
3
>>> np.size(a,0)
2


numpy.ma.soften_mask   ma.soften_mask(self) = <numpy.ma.core._frommethod object>

Force the mask to soft. Whether the mask of a masked array is hard or soft is determined by its hardmask property. soften_mask sets hardmask to False.  See also  ma.MaskedArray.hardmask


numpy.ma.sort   ma.sort(a, axis=- 1, kind=None, order=None, endwith=True, fill_value=None)[source]

Return a sorted copy of the masked array. Equivalent to creating a copy of the array and applying the MaskedArray sort() method. Refer to MaskedArray.sort for the full documentation  See also  MaskedArray.sort

equivalent method


numpy.ma.squeeze   ma.squeeze(*args, **kwargs) = <numpy.ma.core._convert2ma object>

Remove axes of length one from a.  Parameters

aarray_like

Input data.
axisNone or int or tuple of ints, optional

 New in version 1.7.0.  Selects a subset of the entries of length one in the shape. If an axis is selected with shape entry greater than one, an error is raised.    Returns

squeezedMaskedArray

The input array, but with all or a subset of the dimensions of length 1 removed. This is always a itself or a view into a. Note that if all axes are squeezed, the result is a 0d array and not a scalar.    Raises
 ValueError

If axis is not None, and an axis being squeezed is not of length 1      See also  expand_dims

The inverse operation, adding entries of length one  reshape

Insert, remove, and combine dimensions, and resize existing ones    Examples >>> x = np.array([[[0], [1], [2]]])
>>> x.shape
(1, 3, 1)
>>> np.squeeze(x).shape
(3,)
>>> np.squeeze(x, axis=0).shape
(3, 1)
>>> np.squeeze(x, axis=1).shape
Traceback (most recent call last):
...
ValueError: cannot select an axis to squeeze out which has size not equal to one
>>> np.squeeze(x, axis=2).shape
(1, 3)
>>> x = np.array([[1234]])
>>> x.shape
(1, 1)
>>> np.squeeze(x)
array(1234)  # 0d array
>>> np.squeeze(x).shape
()
>>> np.squeeze(x)[()]
1234


numpy.ma.stack   ma.stack(*args, **kwargs) = <numpy.ma.extras._fromnxfunction_seq object>

Join a sequence of arrays along a new axis. The axis parameter specifies the index of the new axis in the dimensions of the result. For example, if axis=0 it will be the first dimension and if axis=-1 it will be the last dimension.  New in version 1.10.0.   Parameters

arrayssequence of array_like

Each array must have the same shape.
axisint, optional

The axis in the result array along which the input arrays are stacked.
outndarray, optional

If provided, the destination to place the result. The shape must be correct, matching that of what stack would have returned if no out argument were specified.    Returns

stackedndarray

The stacked array has one more dimension than the input arrays.      See also  concatenate

Join a sequence of arrays along an existing axis.  block

Assemble an nd-array from nested lists of blocks.  split

Split array into a list of multiple sub-arrays of equal size.    Notes The function is applied to both the _data and the _mask, if any. Examples >>> arrays = [np.random.randn(3, 4) for _ in range(10)]
>>> np.stack(arrays, axis=0).shape
(10, 3, 4)
 >>> np.stack(arrays, axis=1).shape
(3, 10, 4)
 >>> np.stack(arrays, axis=2).shape
(3, 4, 10)
 >>> a = np.array([1, 2, 3])
>>> b = np.array([4, 5, 6])
>>> np.stack((a, b))
array([[1, 2, 3],
       [4, 5, 6]])
 >>> np.stack((a, b), axis=-1)
array([[1, 4],
       [2, 5],
       [3, 6]])


numpy.ma.std   ma.std(self, axis=None, dtype=None, out=None, ddof=0, keepdims=<no value>) = <numpy.ma.core._frommethod object>

Returns the standard deviation of the array elements along given axis. Masked entries are ignored. Refer to numpy.std for full documentation.  See also  numpy.ndarray.std

corresponding function for ndarrays  numpy.std

Equivalent function


numpy.ma.sum   ma.sum(self, axis=None, dtype=None, out=None, keepdims=<no value>) = <numpy.ma.core._frommethod object>

Return the sum of the array elements over the given axis. Masked elements are set to 0 internally. Refer to numpy.sum for full documentation.  See also  numpy.ndarray.sum

corresponding function for ndarrays  numpy.sum

equivalent function    Examples >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
>>> x
masked_array(
  data=[[1, --, 3],
        [--, 5, --],
        [7, --, 9]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=999999)
>>> x.sum()
25
>>> x.sum(axis=1)
masked_array(data=[4, 5, 16],
             mask=[False, False, False],
       fill_value=999999)
>>> x.sum(axis=0)
masked_array(data=[8, 5, 12],
             mask=[False, False, False],
       fill_value=999999)
>>> print(type(x.sum(axis=0, dtype=np.int64)[0]))
<class 'numpy.int64'>


numpy.ma.swapaxes   ma.swapaxes(self, *args, **params) a.swapaxes(axis1, axis2) = <numpy.ma.core._frommethod object>
  Return a view of the array with axis1 and axis2 interchanged. Refer to numpy.swapaxes for full documentation.  See also  numpy.swapaxes

equivalent function


numpy.ma.trace   ma.trace(self, offset=0, axis1=0, axis2=1, dtype=None, out=None) a.trace(offset=0, axis1=0, axis2=1, dtype=None, out=None) = <numpy.ma.core._frommethod object>
  Return the sum along diagonals of the array. Refer to numpy.trace for full documentation.  See also  numpy.trace

equivalent function


numpy.ma.transpose   ma.transpose(a, axes=None)[source]

Permute the dimensions of an array. This function is exactly equivalent to numpy.transpose.  See also  numpy.transpose

Equivalent function in top-level NumPy module.    Examples >>> import numpy.ma as ma
>>> x = ma.arange(4).reshape((2,2))
>>> x[1, 1] = ma.masked
>>> x
masked_array(
  data=[[0, 1],
        [2, --]],
  mask=[[False, False],
        [False,  True]],
  fill_value=999999)
 >>> ma.transpose(x)
masked_array(
  data=[[0, 2],
        [1, --]],
  mask=[[False, False],
        [False,  True]],
  fill_value=999999)


numpy.ma.vander   ma.vander(x, n=None)[source]

Generate a Vandermonde matrix. The columns of the output matrix are powers of the input vector. The order of the powers is determined by the increasing boolean argument. Specifically, when increasing is False, the i-th output column is the input vector raised element-wise to the power of N - i - 1. Such a matrix with a geometric progression in each row is named for Alexandre- Theophile Vandermonde.  Parameters

xarray_like

1-D input array.
Nint, optional

Number of columns in the output. If N is not specified, a square array is returned (N = len(x)).
increasingbool, optional

Order of the powers of the columns. If True, the powers increase from left to right, if False (the default) they are reversed.  New in version 1.9.0.     Returns

outndarray

Vandermonde matrix. If increasing is False, the first column is x^(N-1), the second x^(N-2) and so forth. If increasing is True, the columns are x^0, x^1, ..., x^(N-1).      See also  polynomial.polynomial.polyvander
  Notes Masked values in the input array result in rows of zeros. Examples >>> x = np.array([1, 2, 3, 5])
>>> N = 3
>>> np.vander(x, N)
array([[ 1,  1,  1],
       [ 4,  2,  1],
       [ 9,  3,  1],
       [25,  5,  1]])
 >>> np.column_stack([x**(N-1-i) for i in range(N)])
array([[ 1,  1,  1],
       [ 4,  2,  1],
       [ 9,  3,  1],
       [25,  5,  1]])
 >>> x = np.array([1, 2, 3, 5])
>>> np.vander(x)
array([[  1,   1,   1,   1],
       [  8,   4,   2,   1],
       [ 27,   9,   3,   1],
       [125,  25,   5,   1]])
>>> np.vander(x, increasing=True)
array([[  1,   1,   1,   1],
       [  1,   2,   4,   8],
       [  1,   3,   9,  27],
       [  1,   5,  25, 125]])
 The determinant of a square Vandermonde matrix is the product of the differences between the values of the input vector: >>> np.linalg.det(np.vander(x))
48.000000000000043 # may vary
>>> (5-3)*(5-2)*(5-1)*(3-2)*(3-1)*(2-1)
48


numpy.ma.var   ma.var(self, axis=None, dtype=None, out=None, ddof=0, keepdims=<no value>) = <numpy.ma.core._frommethod object>

Compute the variance along the specified axis. Returns the variance of the array elements, a measure of the spread of a distribution. The variance is computed for the flattened array by default, otherwise over the specified axis.  Parameters

aarray_like

Array containing numbers whose variance is desired. If a is not an array, a conversion is attempted.
axisNone or int or tuple of ints, optional

Axis or axes along which the variance is computed. The default is to compute the variance of the flattened array.  New in version 1.7.0.  If this is a tuple of ints, a variance is performed over multiple axes, instead of a single axis or all the axes as before.
dtypedata-type, optional

Type to use in computing the variance. For arrays of integer type the default is float64; for arrays of float types it is the same as the array type.
outndarray, optional

Alternate output array in which to place the result. It must have the same shape as the expected output, but the type is cast if necessary.
ddofint, optional

“Delta Degrees of Freedom”: the divisor used in the calculation is N - ddof, where N represents the number of elements. By default ddof is zero.
keepdimsbool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. If the default value is passed, then keepdims will not be passed through to the var method of sub-classes of ndarray, however any non-default value will be. If the sub-class’ method does not implement keepdims any exceptions will be raised.
wherearray_like of bool, optional

Elements to include in the variance. See reduce for details.  New in version 1.20.0.     Returns

variancendarray, see dtype parameter above

If out=None, returns a new array containing the variance; otherwise, a reference to the output array is returned.      See also
std, mean, nanmean, nanstd, nanvar

Output type determination
  Notes The variance is the average of the squared deviations from the mean, i.e., var = mean(x), where x = abs(a - a.mean())**2. The mean is typically calculated as x.sum() / N, where N = len(x). If, however, ddof is specified, the divisor N - ddof is used instead. In standard statistical practice, ddof=1 provides an unbiased estimator of the variance of a hypothetical infinite population. ddof=0 provides a maximum likelihood estimate of the variance for normally distributed variables. Note that for complex numbers, the absolute value is taken before squaring, so that the result is always real and nonnegative. For floating-point input, the variance is computed using the same precision the input has. Depending on the input data, this can cause the results to be inaccurate, especially for float32 (see example below). Specifying a higher-accuracy accumulator using the dtype keyword can alleviate this issue. Examples >>> a = np.array([[1, 2], [3, 4]])
>>> np.var(a)
1.25
>>> np.var(a, axis=0)
array([1.,  1.])
>>> np.var(a, axis=1)
array([0.25,  0.25])
 In single precision, var() can be inaccurate: >>> a = np.zeros((2, 512*512), dtype=np.float32)
>>> a[0, :] = 1.0
>>> a[1, :] = 0.1
>>> np.var(a)
0.20250003
 Computing the variance in float64 is more accurate: >>> np.var(a, dtype=np.float64)
0.20249999932944759 # may vary
>>> ((1-0.55)**2 + (0.1-0.55)**2)/2
0.2025
 Specifying a where argument: >>> a = np.array([[14, 8, 11, 10], [7, 9, 10, 11], [10, 15, 5, 10]])
>>> np.var(a)
6.833333333333333 # may vary
>>> np.var(a, where=[[True], [True], [False]])
4.0


numpy.ma.vstack   ma.vstack(*args, **kwargs) = <numpy.ma.extras._fromnxfunction_seq object>

Stack arrays in sequence vertically (row wise). This is equivalent to concatenation along the first axis after 1-D arrays of shape (N,) have been reshaped to (1,N). Rebuilds arrays divided by vsplit. 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 first axis. 1-D arrays must have the same length.    Returns

stackedndarray

The array formed by stacking the given arrays, will be at least 2-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.  hstack

Stack arrays in sequence horizontally (column wise).  dstack

Stack arrays in sequence depth wise (along third axis).  column_stack

Stack 1-D arrays as columns into a 2-D array.  vsplit

Split an array into multiple sub-arrays vertically (row-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.vstack((a,b))
array([[1, 2, 3],
       [4, 5, 6]])
 >>> a = np.array([[1], [2], [3]])
>>> b = np.array([[4], [5], [6]])
>>> np.vstack((a,b))
array([[1],
       [2],
       [3],
       [4],
       [5],
       [6]])


numpy.ma.where   ma.where(condition, x=<no value>, y=<no value>)[source]

Return a masked array with elements from x or y, depending on condition.  Note When only condition is provided, this function is identical to nonzero. The rest of this documentation covers only the case where all three arguments are provided.   Parameters

conditionarray_like, bool

Where True, yield x, otherwise yield y.
x, yarray_like, optional

Values from which to choose. x, y and condition need to be broadcastable to some shape.    Returns

outMaskedArray

An masked array with masked elements where the condition is masked, elements from x where condition is True, and elements from y elsewhere.      See also  numpy.where

Equivalent function in the top-level NumPy module.  nonzero

The function that is called when x and y are omitted    Examples >>> x = np.ma.array(np.arange(9.).reshape(3, 3), mask=[[0, 1, 0],
...                                                    [1, 0, 1],
...                                                    [0, 1, 0]])
>>> x
masked_array(
  data=[[0.0, --, 2.0],
        [--, 4.0, --],
        [6.0, --, 8.0]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=1e+20)
>>> np.ma.where(x > 5, x, -3.1416)
masked_array(
  data=[[-3.1416, --, -3.1416],
        [--, -3.1416, --],
        [6.0, --, 8.0]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=1e+20)


numpy.ma.zeros   ma.zeros(shape, dtype=float, order='C', *, like=None) = <numpy.ma.core._convert2ma object>

Return a new array of given shape and type, filled with zeros.  Parameters

shapeint or tuple of ints

Shape of the new array, e.g., (2, 3) or 2.
dtypedata-type, optional

The desired 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 zeros with the given shape, dtype, and order.      See also  zeros_like

Return an array of zeros with shape and type of input.  empty

Return a new uninitialized array.  ones

Return a new array setting values to one.  full

Return a new array of given shape filled with value.    Examples >>> np.zeros(5)
array([ 0.,  0.,  0.,  0.,  0.])
 >>> np.zeros((5,), dtype=int)
array([0, 0, 0, 0, 0])
 >>> np.zeros((2, 1))
array([[ 0.],
       [ 0.]])
 >>> s = (2,2)
>>> np.zeros(s)
array([[ 0.,  0.],
       [ 0.,  0.]])
 >>> np.zeros((2,), dtype=[('x', 'i4'), ('y', 'i4')]) # custom dtype
array([(0, 0), (0, 0)],
      dtype=[('x', '<i4'), ('y', '<i4')])