torch.hsplit

torch.hsplit(input, indices_or_sections) Tensor 列表

input(一个具有一个或多个维度的张量)根据indices_or_sections水平拆分成多个张量。每个拆分部分是input的一个视图。

如果 input 是一维的,这相当于调用 torch.tensor_split(input, indices_or_sections, dim=0)(分割维度为零)。如果 input 具有二维或更多维度,则相当于调用 torch.tensor_split(input, indices_or_sections, dim=1)(分割维度为 1)。特别地,如果 indices_or_sections 是一个整数且不能均匀划分分割维度,则会抛出运行时错误。

此函数基于 NumPy 的 numpy.hsplit()

参数
示例:
>>> 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.hsplit(t, 2)
(tensor([[ 0.,  1.],
         [ 4.,  5.],
         [ 8.,  9.],
         [12., 13.]]),
 tensor([[ 2.,  3.],
         [ 6.,  7.],
         [10., 11.],
         [14., 15.]]))
>>> torch.hsplit(t, [3, 6])
(tensor([[ 0.,  1.,  2.],
         [ 4.,  5.,  6.],
         [ 8.,  9., 10.],
         [12., 13., 14.]]),
 tensor([[ 3.],
         [ 7.],
         [11.],
         [15.]]),
 tensor([], size=(4, 0)))
本页目录