Transform List to Tensor more accurat
I want to return in the Dataloader a list. 
But to return it, its need to be a tensor right? 
So I transform it but in this process information is lost, is there another way to do this?

pt_tensor_from_list = torch.tensor(pose_transform)
pt_tensor_from_list = torch.FloatTensor(pose_transform)


I excpect the output: 


  ([[-0.0003000000142492354, -0.0008999999845400453,
  0.00039999998989515007, 0], [0.0010000000474974513, -0.00019999999494757503, 0.0003000000142492354, 0], [0.00019999999494757503, -0.0005000000237487257,
  -0.0008999999845400453, 0], [5.484399795532227, -24.28619956970215, 117.5000991821289, 1])


But it is: 


  ([[ -0.0003, -0.0009, 0.0004, 0.0000],
      [ 0.0010, -0.0002, 0.0003, 0.0000],
      [ 0.0002, -0.0005, -0.0009, 0.0000],
      [ 5.4844, -24.2862, 117.5001, 1.0000]])



You are not losing any information during such conversion. The reason why it looks like that, more compactly, is as when you are printing a tensor, it invokes __str__() or __repr__() methods and it makes your tensor looks more pretty. As you can find here torch.Tensor uses a kind of internal tensor formatter called _tensor_str. If you look inside the code link you will find that by default parameter precision is set to 4:


  precision: Number of digits of precision for floating point output          (default = 4).


That's why you have only 4 digits for tensor values when printing the tensor. But actually, values stored in a tensor are the same as in original list. 

Here is small example to get an idea:

Code:

import torch

test_list = ([[-0.0003000000142492354, -0.0008999999845400453, 0.00039999998989515007, 0],
              [0.0010000000474974513, -0.00019999999494757503, 0.0003000000142492354, 0],
              [0.00019999999494757503, -0.0005000000237487257, -0.0008999999845400453, 0],
              [5.484399795532227, -24.28619956970215, 117.5000991821289, 1]])

print('Original values:')
for i in test_list:
    for j in i:
        print(j)

pt_tensor_from_list = torch.FloatTensor(test_list)

print('When printing FloatTensor:')
print(pt_tensor_from_list.dtype, pt_tensor_from_list, sep='\n')

print('When printing each value separately:')
for i in pt_tensor_from_list:
    for j in i:
        print(j.item())


Output:

Original values:
-0.0003000000142492354
-0.0008999999845400453
0.00039999998989515007
0
0.0010000000474974513
-0.00019999999494757503
0.0003000000142492354
0
0.00019999999494757503
-0.0005000000237487257
-0.0008999999845400453
0
5.484399795532227
-24.28619956970215
117.5000991821289
1
When printing FloatTensor:
torch.float32
tensor([[-3.0000e-04, -9.0000e-04,  4.0000e-04,  0.0000e+00],
        [ 1.0000e-03, -2.0000e-04,  3.0000e-04,  0.0000e+00],
        [ 2.0000e-04, -5.0000e-04, -9.0000e-04,  0.0000e+00],
        [ 5.4844e+00, -2.4286e+01,  1.1750e+02,  1.0000e+00]])
When printing each value separately:
-0.0003000000142492354
-0.0008999999845400453
0.00039999998989515007
0.0
0.0010000000474974513
-0.00019999999494757503
0.0003000000142492354
0.0
0.00019999999494757503
-0.0005000000237487257
-0.0008999999845400453
0.0
5.484399795532227
-24.28619956970215
117.5000991821289
1.0


As you can see, we are getting the same values when printing each value separately.

BUT you can lose some info if you choose the wrong tensor types, for example HalfTensor instead of FloatTensor. Here is an example:

Code:

pt_tensor_from_list = torch.HalfTensor(test_list)

print('When printing HalfTensor:')
print(pt_tensor_from_list.dtype, pt_tensor_from_list, sep='\n')

print('When printing each value separately:')
for i in pt_tensor_from_list:
    for j in i:
        print(j.item())


Output:

When printing HalfTensor:
torch.float16
tensor([[-2.9993e-04, -8.9979e-04,  4.0007e-04,  0.0000e+00],
        [ 1.0004e-03, -2.0003e-04,  2.9993e-04,  0.0000e+00],
        [ 2.0003e-04, -5.0020e-04, -8.9979e-04,  0.0000e+00],
        [ 5.4844e+00, -2.4281e+01,  1.1750e+02,  1.0000e+00]],
       dtype=torch.float16)
When printing each value separately:
-0.0002999305725097656
-0.0008997917175292969
0.0004000663757324219
0.0
0.0010004043579101562
-0.00020003318786621094
0.0002999305725097656
0.0
0.00020003318786621094
-0.0005002021789550781
-0.0008997917175292969
0.0
5.484375
-24.28125
117.5
1.0


As you can notice now the values are (a little bit) different. Visit pytorch tensor docs to learn more about different types of torch.tensor.
