fn

flatten

Tensor
flatten(input: Tensor, start_axis: int = ..., end_axis: int = ...)
source

Collapse a contiguous range of dimensions into a single dim.

All dimensions from start_axis to end_axis (inclusive) are merged into one, preserving row-major order of the original elements. Often used to feed a feature map into a fully-connected head.

Parameters

inputTensor
Source tensor.
start_axisint= 0
First dimension to flatten.
end_axisint= -1
Last dimension to flatten (inclusive).

Returns

Tensor

Tensor whose rank is reduced by end_axis - start_axis.

Notes

The merged dim has size k=startendshape[k]\prod_{k=\text{start}}^{\text{end}} \text{shape}[k]. The result is a view when input is contiguous in the flattened range, otherwise a copy.

Examples

>>> import lucid
>>> x = lucid.zeros(2, 3, 4)
>>> lucid.flatten(x).shape
(24,)
>>> lucid.flatten(x, 1, 2).shape
(2, 12)