torch.vsplit¶
- torch.vsplit(input, indices_or_sections) List of Tensors¶
将
input(一个具有两个或更多维度的张量)根据indices_or_sections垂直分割成多个张量。每个分割都是input的一个视图。这等同于调用 torch.tensor_split(input, indices_or_sections, dim=0) (分割维度是 0),除了如果
indices_or_sections是一个整数 它必须均匀地分割分割维度,否则会抛出一个运行时错误。此函数基于 NumPy 的
numpy.vsplit()。- Parameters
输入 (张量) – 要分割的张量。
indices_or_sections (整数 或 列表 或 元组 的 整数) – 参见
torch.tensor_split()中的参数。
- Example::
>>> t = torch.arange(16.0).reshape(4,4) >>> t tensor([[ 0., 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., 11.], [12., 13., 14., 15.]]) >>> torch.vsplit(t, 2) (tensor([[0., 1., 2., 3.], [4., 5., 6., 7.]]), tensor([[ 8., 9., 10., 11.], [12., 13., 14., 15.]])) >>> torch.vsplit(t, [3, 6]) (tensor([[ 0., 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., 11.]]), tensor([[12., 13., 14., 15.]]), tensor([], size=(0, 4)))