qnl
April 21, 2019, 9:38am
#1
Hi.

I want to append sparse flaot tensor.

```
t0 = torch.FloatTensor([0.0,1.0,2.0]).to_sparse()
t1 = torch.FloatTensor([3.0,4.0,5.0]).to_sparse()
t2 = torch.cat([t0,t1]) # want [[0,1,2],[3,4,5]] but got [0,1,2,3,4,5]
#t2 = t2.reshape(2,3) # got "reshape is not implemented for sparse tensors"
```

Are there something way to get [[0,1,2],[3,4,5]] ?
Thanks.

Based on your desired output, Iām not sure if a sparse tensor is really what you are looking for, as it looks like you would just like to stack both tensors.
However, would this work for you:

```
t2 = torch.stack([t0,t1])
tensor(indices=tensor([[0, 0, 1, 1, 1],
[1, 2, 0, 1, 2]]),
values=tensor([1., 2., 3., 4., 5.]),
size=(2, 3), nnz=5, layout=torch.sparse_coo)
```

1 Like

qnl
April 21, 2019, 12:19pm
#3
I solved it by myself.

```
t0 = torch.FloatTensor([[0.0,1.0,2.0]]).to_sparse() # not "[0,1,2]" but "[[0,1,2]]"
t1 = torch.FloatTensor([[3.0,4.0,5.0]]).to_sparse()
t2 = torch.cat([t0,t1]) # [[0,1,2],[3,4,5]]
```

I misunderstood ā3ā is ā1x3ā.

Thanks