[PYTHON] TypeError: mul (): argument'other' (position 1) must be Tensor, not list Solution for error

When I ran the following program, I got the following error.

Execution statement


seqlen = torch.tensor(10)
mask = [[1] * seqlen]

Error statement


TypeError:mul():argument 'other' (position 1) must be Tensor,not list

Cause

Error from Pytorch version It seems that it is impossible to calculate torch.tensor and list from torch> 0.3.1.

Solution

  1. Lower the version of pytorch to torch <= 0.31
  2. Modify the program as follows

Change before


mask = [[1] * seqlen]

After change


mask = [[1] * int(seqlen)]

Recommended Posts

TypeError: mul (): argument'other' (position 1) must be Tensor, not list Solution for error
Python 3 migration> TypeError: must be real number, not map support> change map () to list (map ())