bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / _core / _multiarray_umath / putmask
built-in
numpy._core._multiarray_umath:putmask
Signature
built-in
putmask ( a , / , mask , values ) Summary
Changes elements of an array based on conditional and input values.
Extended Summary
Sets a.flat[n] = values[n] for each n where mask.flat[n]==True.
If values is not the same size as a and mask then it will repeat. This gives behavior different from a[mask] = values.
Parameters
a: ndarrayTarget array.
mask: array_likeBoolean mask array. It has to be the same shape as
a.values: array_likeValues to put into
awheremaskis True. Ifvaluesis smaller thanait will be repeated.
Examples
import numpy as np x = np.arange(6).reshape(2, 3) np.putmask(x, x>2, x**2) xIf `values` is smaller than `a` it is repeated:
x = np.arange(5) np.putmask(x, x>1, [-33, -44]) x
See also
Aliases
-
numpy._core._multiarray_umath.putmask