0
0

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 3 years have passed since last update.

【pytorch】forループで作ったtensorを空のリストを作らずに結合

Last updated at Posted at 2022-10-27

解決策

グラフ特徴量の計算を行う関数の一部
for i in range(num_nodes):
    ############省略############
    edge_idx, edge_att = coalesce(edge_idx, edge_att, num_nodes, num_nodes)
    try:
        edge_idx_list = torch.stack((edge_idx_list, edge_idx), dim = 0)
    except:
        edge_idx_list = edge_idx

個人的なメモ:問題

GNNの入力のためにエッジのインデックスとエッジ特徴量の配列をグラフごとに計算し、datasetにぶち込むためにそれぞれを一つのtensorに収めようとした。
計算後のtensorを空のリストにappendして最後にtorchに変換する方法を試みたが、リスト内の要素の型がtorch.tensorになっていたりリストからtorch.tensorに変換しようとするのにうまい方法が分からなかった

参照

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?