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

TypeError:mul():argument 'other' (position 1) must be Tensor,not listエラーの解決法

Posted at

以下のプログラムを実行した際に次のようなエラーが出た。

実行文
seqlen = torch.tensor(10)
mask = [[1] * seqlen]
エラー文
TypeError:mul():argument 'other' (position 1) must be Tensor,not list

原因

Pytorchのバージョン由来のエラー
torch>0.3.1からtorch.tensorとリストの演算が不可能になっているらしい

解決法

  1. pytorchのバージョンをtorch<=0.3.1に下げる
  2. 次のようにプログラムを修正する
変更前
mask = [[1] * seqlen]
変更後
mask = [[1] * int(seqlen)]
0
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
0
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?