How can I assign a list to a torch.tensor?
Assume that I have a list [(0,0),(1,0),(1,1)] and another list [4,5,6] and a matrix X with size is (3,2). I am trying to assign the list to the matrix like X[0,0] = 4, X[1,0] = 5 and X[1,1] = 6. But it seems like I have a problem of assigning a list to tensor
x = torch.zeros(3,2)
indices = [(0,0),(1,0),(1,1)]
value = [4,5,6]
x[indices] = values

Error:
TypeError                                 Traceback (most recent call last)
&lt;ipython-input-7-dec4e6a479a5&gt; in &lt;module&gt;
     
   4 indices = [(0, 0), (1, 0), (1, 1)]
 
   5 values = [4, 5, 6]

----&gt; 6 x[indices] = values

TypeError: can't assign a list to a torch.FloatTensor


In general, the answer to &quot;how do I change a list to a Tensor&quot; is to use torch.Tensor(list). But that will not solve your actual problem here.
One way would be to associate the index and value and then iterate over them:
for (i,v) in zip(indices,values) :
   x[i] = v

