fn

take

Tensor
take(input: Tensor, indices: Tensor)
source

Return elements of input at the given flat indices.

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

Parameters

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

Returns

Tensor

Tensor of the same shape as indices.

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])