PyTorch torch.chunk function
PyTorch torch reference manual
torch.chunk is a function in PyTorch used to split a tensor into chunks along a specified dimension.
Function definition
torch.chunk(tensor, chunks, dim)
Usage examples
Example
import
torch
x
=
torch.
arange
(
12
)
.
reshape
(
3
,
4
)
Split into 3 chunks
result
=
torch.
chunk
(
x
,
3
,
dim
=
0
)
(
"Number of chunks:"
,
len
(
result
)
)
for
i
,
t
in
enumerate
(
result
)
:
(
f
"Chunk {i}:"
,
t.
shape
)