torch.dsplit
- torch.dsplit(input, indices_or_sections) → Tensors 列表
-
将
input
(一个具有三个或更多维度的张量)根据indices_or_sections
深度方向分割成多个张量。每个分割结果都是input
的一个视图。这等同于调用 torch.tensor_split(input, indices_or_sections, dim=2)(其中分割维度为 2)。如果
indices_or_sections
是一个整数且不能均匀划分分割维度,则会抛出运行时错误。此函数基于 NumPy 的
numpy.dsplit()
。- 参数
-
-
input (Tensor) – 需要拆分的张量。
-
indices_or_sections (int 或 list 或 tuple of ints) – 请参阅
torch.tensor_split()
中的参数说明。
-
- 示例:
-
>>> 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]) (tensor([[[ 0., 1., 2.], [ 4., 5., 6.]], [[ 8., 9., 10.], [12., 13., 14.]]]), tensor([[[ 3.], [ 7.]], [[11.], [15.]]]), tensor([], size=(2, 2, 0)))