dpnp.putmask

dpnp.putmask(a, /, mask, values)[source]

Changes elements of an array based on conditional and input values.

For full documentation refer to numpy.putmask.

Parameters:
  • a ({dpnp.ndarray, usm_ndarray}) -- Target array.

  • mask ({dpnp.ndarray, usm_ndarray}) -- Boolean mask array. It has to be the same shape as a.

  • values ({scalar, array_like}) -- Values to put into a where mask is True. If values is smaller than a, then it will be repeated.

See also

dpnp.place

Change elements of an array based on conditional and input values.

dpnp.put

Replaces specified elements of an array with given values.

dpnp.take

Take elements from an array along an axis.

dpnp.copyto

Copies values from one array to another, broadcasting as necessary.

Examples

>>> import dpnp as np
>>> x = np.arange(6).reshape(2, 3)
>>> np.putmask(x, x>2, x**2)
>>> x
array([[ 0,  1,  2],
       [ 9, 16, 25]])

If values is smaller than a it is repeated:

>>> x = np.arange(5)
>>> np.putmask(x, x>1, np.array([-33, -44]))
>>> x
array([  0,   1, -33, -44, -33])