This is a pre-release version (2.5.0.dev0+git20251130.2de293a). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / ma / core / where

function

numpy.ma.core:where

source: build-install/usr/lib/python3.14/site-packages/numpy/ma/core.py :7913

Signature

def   where ( condition x = <no value> y = <no value> )

Summary

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

Extended Summary

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 condition need to be broadcastable to some shape.

Returns

out : MaskedArray

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

Examples

import numpy as np
x = np.ma.array(np.arange(9.).reshape(3, 3), mask=[[0, 1, 0],
                                                   [1, 0, 1],
                                                   [0, 1, 0]])
x
np.ma.where(x > 5, x, -3.1416)

See also

nonzero

The function that is called when x and y are omitted

numpy.where

Equivalent function in the top-level NumPy module.

Aliases

  • numpy.ma.where