fn

hsplit

list[Tensor]
hsplit(x: Tensor, indices_or_sections: int | Sequence[int])
source

Split a tensor horizontally (along axis 1 for rank 2\geq 2).

NumPy-style horizontal split: cuts the input column-wise along axis 1 for tensors of rank 2\geq 2. For 1-D inputs the axis collapses to 0, since there is only one dimension available.

Parameters

xTensor
Input tensor. At least 1-D.
indices_or_sectionsint | Sequence[int]
  • int: number of (near-)equal-sized splits. If the axis length is not divisible by k, the first axis_len % k pieces get one extra element.
  • Sequence[int]: cut indices along the split axis (axis 1 for rank 2\geq 2, axis 0 for 1-D).

Returns

list[Tensor]

Sub-tensors whose concatenation along the split axis reproduces x.

Notes

Companion to vsplit (axis 0) and dsplit (axis 2). The axis-selection rule

axis={0,ndim(x)=1,1,ndim(x)2,\text{axis} = \begin{cases} 0, & \text{ndim}(x) = 1, \\ 1, & \text{ndim}(x) \geq 2, \end{cases}

matches NumPy's convention so that 1-D inputs behave intuitively rather than raising on the missing column axis.

Examples

>>> import lucid
>>> x = lucid.arange(12).reshape(3, 4)
>>> [s.shape for s in lucid.hsplit(x, 2)]
[(3, 2), (3, 2)]
>>> v = lucid.arange(6)
>>> [s.shape for s in lucid.hsplit(v, 3)]
[(2,), (2,), (2,)]