TensorName.chunk( blocknum , dim)
A
=
t
o
r
c
h
.
r
a
n
d
i
n
t
(
0
,
255
,
(
2
,
3
,
4
,
4
)
)
分
割
的
结
果
为
t
u
p
l
e
A = torch.randint(0, 255, (2, 3, 4, 4))分割的结果为tuple
A=torch.randint(0,255,(2,3,4,4))分割的结果为tuple
A=[2,3,4,4] ,A.chunk(2,dim=0)
A=[2,3,4,4] ,A.chunk(2,dim=1)
A=[2,3,4,4] ,A.chunk(2,dim=2)
A=[2,3,4,4] ,A.chunk(2,dim=3)
chunk 和 split
split要求分割正好整除,但是如官网例子https://pytorch.org/docs/stable/generated/torch.split.html#torch.split可以设置每块的大小:
torch.split(a, [1,4])
(tensor([[0, 1]]),
tensor([[2, 3],
[4, 5],
[6, 7],
[8, 9]]))
UNBIND:拆解矩阵某个维度,并返回切片
# https://pytorch.org/docs/master/generated/torch.unbind.html
torch.unbind(torch.tensor([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]))
# (tensor([1, 2, 3]), tensor([4, 5, 6]), tensor([7, 8, 9]))