TUTORIALAI & dataFETCHED
PyTorch torch.chunk 函数
PyTorch torch.chunk 函数 Pytorch torch 参考手册 torch.chunk 是 PyTorch 中用于将张量沿指定维度分块的函数。 函数定义 torch.chunk(tensor, chunks, dim) 使用示例 实例 [mycode4 type='python'] import torch x = torch.arange(12).reshape(3, 4)..
Updated 7/16/2026
Tutorial detail pages default to noindex.
PyTorch torch.chunk 函数
torch.chunk 是 PyTorch 中用于将张量沿指定维度分块的函数。
函数定义
torch.chunk(tensor, chunks, dim)
使用示例
实例
import torch
x = torch.arange(12).reshape(3, 4)
# 分成 3 块
result = torch.chunk(x, 3, dim=0)
print("块数:", len(result))
for i, t in enumerate(result):
print(f"Chunk {i}:", t.shape)
x = torch.arange(12).reshape(3, 4)
# 分成 3 块
result = torch.chunk(x, 3, dim=0)
print("块数:", len(result))
for i, t in enumerate(result):
print(f"Chunk {i}:", t.shape)
Pytorch torch 参考手册