2

I have a tensor with the following characteristics:

<class 'torch.Tensor'>

torch.Size([600, 1])

I would like it to be a column in a data frame.

When I add the tensor to a df as is, I get the following for one of the rows.

tensor([-0.1186])

How do I get rid of the tensor([])? So that each row is just a number. For this row, I would just want -0.1186.

iacob
  • 20,084
  • 6
  • 92
  • 119
Mattpats
  • 414
  • 2
  • 9
  • 21
  • 1
    Does this help you? https://stackoverflow.com/questions/49768306/pytorch-tensor-to-numpy-array – Mobina Jul 29 '20 at 22:01

1 Answers1

0

If you squeeze your tensor from size (600,1) to size (600) you can directly add its values as a new column to a DataFrame:

df['newcol'] = my_tensor.squeeze()
iacob
  • 20,084
  • 6
  • 92
  • 119