dcoukos
(Dimitri Coukos)
February 4, 2020, 7:58am
#1
I am trying to make a tensor from a list of tensors, which is throwing a ValueError: only one element tensors can be converted to Python scalars .

my setup is like so:

```
I have calculated three tensors n0, n1, n2
n0 = tensor([-0.4360, -1.1935, -0.8568])
n1 = tensor([ 0.8926, -0.0698, 0.5011])
n2 = tensor([-1.3286, -1.1237, -1.3579])
b = torch.tensor([[n2-n1],
[n0-n2],
[n1-n0]])
```

produces the error
I am having trouble understanding:

Why this way of making a tensor would be undesirable
How to do this in a more pytorch friendly way
Thanks for any help!

raj-rishav
(Rishav Raj)
February 4, 2020, 9:01am
#2
I ain’t sure about the 1st question. But I would use below code for the variable `b`

.

```
b = torch.cat(((n2 - n1).unsqueeze(0), (n0 - n2).unsqueeze(0), (n1 - n0).unsqueeze(0)), 0)
```

G.M
February 4, 2020, 10:08am
#3
For your first question, I think it’s because it is hard to decide whether you want to leave the input tensors as a dimension or you only want the values in it. It’ll be quite confusing.

saty_101
(Satyajit Ghosh)
April 18, 2020, 5:16pm
#4
Have you found the answer to your question? I can’t wrap my head around to get the desired result and want to know why error is coming up.