dpnp.putmask¶
- dpnp.putmask(a, /, mask, values)[source]¶
Changes elements of an array based on conditional and input values.
Sets
a.flat[n] = values[n]for eachnwheremask.flat[n]isTrue.If values is not the same size as a and mask then it will repeat. This gives behavior different from
a[mask] = values.For full documentation refer to
numpy.putmask.- Parameters:
a ({dpnp.ndarray, usm_ndarray}) -- Target array.
mask (array_like) -- Boolean mask array. It has to be the same shape as a.
values ({array_like, scalar}) -- Values to put into a where mask is
True. If values is smaller than a it will be repeated.
Limitations
Input array
aandmaskare expected to have the same shape (unlikenumpy.putmask, which only requires the same size).See also
dpnp.placeChange elements of an array based on conditional and input values.
dpnp.putReplaces specified elements of an array with given values.
dpnp.takeTake elements from an array along an axis.
dpnp.copytoCopies values from one array to another.
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])