fn

narrow

Tensor
narrow(input: Tensor, dim: int, start: int, length: int)
source

Return a contiguous slice of input along dim.

Equivalent to input[..., start:start+length, ...] with the slice applied at position dim. Returns a view — no data copy.

Parameters

inputTensor
Source tensor.
dimint
Dimension to slice.
startint
First index (inclusive).
lengthint
Number of elements to take. Must satisfy start + length <= input.size(dim).

Returns

Tensor

View into input of size length along dim.

Notes

Unlike NumPy slicing, narrow accepts only step 1; for general strided slicing use indexing syntax.

Examples

>>> import lucid
>>> x = lucid.arange(10)
>>> lucid.narrow(x, dim=0, start=3, length=4)
Tensor([3, 4, 5, 6])