Shortcuts

torch.dsplit

torch.dsplit(input, indices_or_sections) List of Tensors

根据 indices_or_sections,将具有三个或更多维度的张量 input 深度拆分为多个张量。每个拆分都是 input 的一个视图。

这等同于调用 torch.tensor_split(input, indices_or_sections, dim=2) (分割维度是 2),除了如果 indices_or_sections 是一个整数 它必须均匀地分割分割维度,否则会抛出一个运行时错误。

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

Parameters
Example::
>>> t = torch.arange(16.0).reshape(2, 2, 4)
>>> t
tensor([[[ 0.,  1.,  2.,  3.],
         [ 4.,  5.,  6.,  7.]],
        [[ 8.,  9., 10., 11.],
         [12., 13., 14., 15.]]])
>>> torch.dsplit(t, 2)
(tensor([[[ 0.,  1.],
        [ 4.,  5.]],
       [[ 8.,  9.],
        [12., 13.]]]),
 tensor([[[ 2.,  3.],
          [ 6.,  7.]],
         [[10., 11.],
          [14., 15.]]]))
>>> torch.dsplit(t, [3, 6])
(张量([[[ 0.,  1.,  2.],
          [ 4.,  5.,  6.]],
         [[ 8.,  9., 10.],
          [12., 13., 14.]]]),
 张量([[[ 3.],
          [ 7.]],
         [[11.],
          [15.]]]),
 张量([], 大小=(2, 2, 0)))
优云智算