Wed Apr 26 09:29:00 UTC 2023 inscode

上级 df352508
import torch
tensor_1 = torch.rand(1, 4, 1)
t1 = tensor_1.expand(5, 4, 6) # 同时扩展第0维和第2维
t2 = tensor_1.expand(5, -1, 6) # 表示第1维不改变大小
tensor_2 = torch.rand(2, 4)
t3 = tensor_2.expand(6, 6, 2, 4) # 在前面扩展两个维度
print(t1.shape) # torch.Size([5, 4, 6])
print(t2.shape) # torch.Size([5, 4, 6])
print(t3.shape) # torch.Size([6, 6, 2, 4])
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册