numpy 1.22.4 Pypi GitHub Homepage
Other Docs
BackRef

Arrays sometimes contain invalid or missing data. When doing operations on such arrays, we wish to suppress invalid values, which is the purpose masked arrays fulfill (an example of typical use is given below).

For example, examine the following array:

>>> x = np.array([2, 1, 3, np.nan, 5, 2, 3, np.nan])

When we try to calculate the mean of the data, the result is undetermined:

>>> np.mean(x)
nan

The mean is calculated using roughly np.sum(x)/len(x) , but since any number added to NaN produces NaN , this doesn't work. Enter masked arrays:

>>> m = np.ma.masked_array(x, np.isnan(x))
>>> m
masked_array(data = [2.0 1.0 3.0 -- 5.0 2.0 3.0 --],
      mask = [False False False  True False False False  True],
      fill_value=1e+20)

Here, we construct a masked array that suppress all NaN values. We may now proceed to calculate the mean of the other values:

>>> np.mean(m)
2.6666666666666665
            <Unimplemented 'footnote' '.. [1] Not-a-Number, a floating point value that is the result of an\n       invalid operation.'>
           
.. moduleauthor:: Pierre Gerard-Marchant
    
.. moduleauthor:: Jarrod Millman
    

Masked Arrays

Arrays sometimes contain invalid or missing data. When doing operations on such arrays, we wish to suppress invalid values, which is the purpose masked arrays fulfill (an example of typical use is given below).

For example, examine the following array:

>>> x = np.array([2, 1, 3, np.nan, 5, 2, 3, np.nan])

When we try to calculate the mean of the data, the result is undetermined:

>>> np.mean(x)
nan

The mean is calculated using roughly np.sum(x)/len(x) , but since any number added to NaN produces NaN , this doesn't work. Enter masked arrays:

>>> m = np.ma.masked_array(x, np.isnan(x))
>>> m
masked_array(data = [2.0 1.0 3.0 -- 5.0 2.0 3.0 --],
      mask = [False False False  True False False False  True],
      fill_value=1e+20)

Here, we construct a masked array that suppress all NaN values. We may now proceed to calculate the mean of the other values:

>>> np.mean(m)
2.6666666666666665
            <Unimplemented 'footnote' '.. [1] Not-a-Number, a floating point value that is the result of an\n       invalid operation.'>
           
.. moduleauthor:: Pierre Gerard-Marchant
    
.. moduleauthor:: Jarrod Millman
    

Examples

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

dask.array.ma.masked_values dask.array.ma.getdata dask.array.ma.masked_invalid scipy.sparse.csgraph._tools.csgraph_from_masked numpy.ma.extras dask.array.ma.average dask.array.ma.masked_where dask.array.ma.set_fill_value scipy.special._logsumexp.logsumexp dask.array.ma.masked_array dask.array.ma.masked_equal dask.array.ma.getmaskarray dask.array.ma.filled numpy.ma.core.MaskedIterator dask.array.ma.masked_inside dask.array.ma.fix_invalid dask.array.ma.masked_outside

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/ma/__init__.py#0
type: <class 'module'>
Commit: