Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.split function

PyTorch torch.split function


PyTorch torch reference manual PyTorch torch reference manual

torch.split is a function in PyTorch used to split a tensor along a specified dimension.

Function definition

torch.split(tensor, split_size, dim)


Usage examples

Example

import

torch

x

=

torch.

arange

(

12

)

.

reshape

(

3

,

4

)

Split along dim=0

result

=

torch.

split

(

x

,

1

,

dim

=

0

)

for

i

,

t

in

enumerate

(

result

)

:

   

print

(

f

"Part {i}:"

)

   

print

(

t

)


PyTorch torch reference manual PyTorch torch reference manual