numpy 1.22.4 Pypi GitHub Homepage
Other Docs
ParametersReturnsBackRef
make_mask(m, copy=False, shrink=True, dtype=<class 'numpy.bool_'>)

Return m as a boolean mask, creating a copy if necessary or requested. The function can accept any sequence that is convertible to integers, or nomask . Does not require that contents must be 0s and 1s, values of 0 are interpreted as False, everything else as True.

Parameters

m : array_like

Potential mask.

copy : bool, optional

Whether to return a copy of m (True) or m itself (False).

shrink : bool, optional

Whether to shrink m to nomask if all its values are False.

dtype : dtype, optional

Data-type of the output mask. By default, the output mask has a dtype of MaskType (bool). If the dtype is flexible, each field has a boolean dtype. This is ignored when m is nomask , in which case nomask is always returned.

Returns

result : ndarray

A boolean mask derived from m.

Create a boolean mask from an array.

Examples

This example is valid syntax, but we were not able to check execution
>>> import numpy.ma as ma
... m = [True, False, True, True]
... ma.make_mask(m) array([ True, False, True, True])
This example is valid syntax, but we were not able to check execution
>>> m = [1, 0, 1, 1]
... ma.make_mask(m) array([ True, False, True, True])
This example is valid syntax, but we were not able to check execution
>>> m = [1, 0, 2, -3]
... ma.make_mask(m) array([ True, False, True, True])

Effect of the :None:None:`shrink` parameter.

This example is valid syntax, but we were not able to check execution
>>> m = np.zeros(4)
... m array([0., 0., 0., 0.])
This example is valid syntax, but we were not able to check execution
>>> ma.make_mask(m)
False
This example is valid syntax, but we were not able to check execution
>>> ma.make_mask(m, shrink=False)
array([False, False, False, False])

Using a flexible dtype .

This example is valid syntax, but we were not able to check execution
>>> m = [1, 0, 1, 1]
... n = [0, 1, 0, 0]
... arr = []
... for man, mouse in zip(m, n):
...  arr.append((man, mouse))
... arr [(1, 0), (0, 1), (1, 0), (1, 0)]
This example is valid syntax, but we were not able to check execution
>>> dtype = np.dtype({'names':['man', 'mouse'],
...  'formats':[np.int64, np.int64]})
... arr = np.array(arr, dtype=dtype)
... arr array([(1, 0), (0, 1), (1, 0), (1, 0)], dtype=[('man', '<i8'), ('mouse', '<i8')])
This example is valid syntax, but we were not able to check execution
>>> ma.make_mask(arr, dtype=dtype)
array([(True, False), (False, True), (True, False), (True, False)],
      dtype=[('man', '|b1'), ('mouse', '|b1')])
See :

Back References

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

numpy.ma.core.make_mask_none

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/core.py#1548
type: <class 'function'>
Commit: