dpnp.place

dpnp.place(a, mask, vals)[source]

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

Similar to dpnp.copyto(a, vals, where=mask), the difference is that dpnp.place uses the first N elements of vals, where N is the number of True values in mask, while dpnp.copyto uses the elements where mask is True.

Note that dpnp.extract does the exact opposite of dpnp.place.

For full documentation refer to numpy.place.

Parameters:
  • a ({dpnp.ndarray, usm_ndarray}) -- Array to put data into.

  • mask ({array_like, scalar}) -- Boolean mask array. Must have the same size as a.

  • vals ({array_like, scalar}) -- Values to put into a. Only the first N elements are used, where N is the number of True values in mask. If vals is smaller than N, it will be repeated, and if elements of a are to be masked, this sequence must be non-empty.

See also

dpnp.copyto

Copies values from one array to another.

dpnp.put

Replaces specified elements of an array with given values.

dpnp.take

Take elements from an array along an axis.

dpnp.extract

Return the elements of an array that satisfy some condition.

Examples

>>> import dpnp as np
>>> a = np.arange(6).reshape(2, 3)
>>> np.place(a, a > 2, [44, 55])
>>> a
array([[ 0,  1,  2],
       [44, 55, 44]])