2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【備忘録】torch.Tensorが入ったlistを二次元のTensorに変換

Posted at
import torch

tensor_list = []
for i in range(3):
    tensor_list.append(torch.rand(3))
print(tensor_list)
# [tensor([0.4824, 0.2966, 0.3177]), tensor([0.5601, 0.0189, 0.4304]), tensor([0.9667, 0.4388, 0.2032])]

tensor_list = torch.stack(tensor_list, dim=0) # これ

print(tensor_list)
# tensor([[0.4824, 0.2966, 0.3177],
#       [0.5601, 0.0189, 0.4304],
#       [0.9667, 0.4388, 0.2032]])
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?