numpy 1.22.4 Pypi GitHub Homepage
Other Docs
ParametersReturns
where(condition, x=<no value>, y=<no value>)
note

When only :None:None:`condition` is provided, this function is identical to :None:None:`nonzero`. The rest of this documentation covers only the case where all three arguments are provided.

Parameters

condition : array_like, bool

Where True, yield x, otherwise yield y.

x, y : array_like, optional

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

Returns

out : MaskedArray

An masked array with :None:None:`masked` elements where the condition is masked, elements from x where :None:None:`condition` is True, and elements from y elsewhere.

Return a masked array with elements from x or y, depending on condition.

See Also

nonzero

The function that is called when x and y are omitted

numpy.where

Equivalent function in the top-level NumPy module.

Examples

This example is valid syntax, but we were not able to check execution
>>> 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)
This example is valid syntax, but we were not able to check execution
>>> 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)
See :

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#7255
type: <class 'function'>
Commit: