torch.vsplit¶
- torch.vsplit(input, indices_or_sections) 张量列表 ¶
根据
indices_or_sections
垂直地将具有两个或更多维度的张量input
拆分成多个张量。每个拆分都是input
的视图。这等效于调用 torch.tensor_split(input, indices_or_sections, dim=0)(拆分维度是 0),但如果
indices_or_sections
是一个整数,则它必须能够整除拆分维度,否则将抛出运行时错误。此函数基于 NumPy 的
numpy.vsplit()
。- 参数
input (Tensor) – 要拆分的张量。
indices_or_sections (int 或 list 或 tuple of ints) – 参见
torch.tensor_split()
中的参数说明。
- 示例:
>>> 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)))