dpnp.take

dpnp.take(x, indices, /, *, axis=None, out=None, mode='wrap')[source]

Take elements from an array along an axis.

For full documentation refer to numpy.take.

Returns:

out -- An array with shape x.shape[:axis] + indices.shape + x.shape[axis + 1:] filled with elements from x.

Return type:

dpnp.ndarray

Limitations

Parameters x and indices are supported either as dpnp.ndarray or dpctl.tensor.usm_ndarray. Parameter indices is supported as 1-D array of integer data type. Parameter out is supported only with default value. Parameter mode is supported with wrap, the default, and clip values. Providing parameter axis is optional when x is a 1-D array. Otherwise the function will be executed sequentially on CPU.

See also

dpnp.compress

Take elements using a boolean mask.

dpnp.take_along_axis

Take elements by matching the array and the index arrays.

Notes

How out-of-bounds indices will be handled. "wrap" - clamps indices to (-n <= i < n), then wraps negative indices. "clip" - clips indices to (0 <= i < n)

Examples

>>> import dpnp as np
>>> x = np.array([4, 3, 5, 7, 6, 8])
>>> indices = np.array([0, 1, 4])
>>> np.take(x, indices)
array([4, 3, 6])

In this example "fancy" indexing can be used.

>>> x[indices]
array([4, 3, 6])
>>> indices = dpnp.array([-1, -6, -7, 5, 6])
>>> np.take(x, indices)
array([8, 4, 4, 8, 8])
>>> np.take(x, indices, mode="clip")
array([4, 4, 4, 8, 8])