Skip to content
fn

take

→Tensor
take(input: Tensor, index: Tensor)

Implementing kernel

C++ engine symbols that back this Python API.

Return elements of input at the given flat index.

The input is treated as if it were flattened in row-major order; the output has the same shape as index. Unlike gather there is no per-axis selection — indices address the entire tensor as a 1-D array.

Parameters

inputTensor
Source tensor.
indexTensor
Integer indices into the flattened input.

Returns

Tensor

Tensor of the same shape as index.

Notes

Useful for sparse lookups when the index pattern does not align with a single axis.

Examples

>>> import lucid
>>> x = lucid.tensor([[1, 2], [3, 4]])
>>> lucid.take(x, lucid.tensor([0, 3]))
Tensor([1, 4])