简体   繁体   English

如何在 4d 火炬张量中获取 3d 张量模块?

[英]How to get modules of 3d tensors in 4d torch tensor?

I have a torch tensor with 4 dimensions.我有一个 4 维的火炬张量。 It's shape is [50, 1, 1, 200].它的形状是 [50, 1, 1, 200]。 I have to get a list with modules of 200 hundred 3d tensors.我必须得到一个包含 20000 个 3d 张量模块的列表。 Which is the easiest way to do so?哪种方法最简单?

Did you try torch.unbind ( https://pytorch.org/docs/stable/generated/torch.unbind.html )?您是否尝试torch.unbindhttps://pytorch.org/docs/stable/generated/torch.unbind.html )?

a = torch.rand(50, 1, 1, 200)
b = torch.unbind(dim=3)

len(b)      # 200
b[0].shape  # torch.Size([50, 1, 1])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM