How to convert numpy array into LongTensor type Variable in PyTorch?
I am trying to convert numpy array into PyTorch LongTensor type Variable as follows:

import numpy as np
import torch as th

y = np.array([1., 1., 1.1478225, 1.1478225, 0.8521775, 0.8521775, 0.4434675])
yth = Variable(th.from_numpy(y)).type(torch.LongTensor)


However the result I am getting is a rounded off version:

tensor([ 1,  1,  1,  1,  0,  0,  0])


How can I keep the precision of numpy array while getting LongTensor variable?

Expected result should be:

tensor([1., 1., 1.1478225, 1.1478225, 0.8521775, 0.8521775, 0.4434675])


LongTensor represents tensors with values of type long / int64 (c.f. table in doc). Your float values are thus converted (i.e. rounded) to integers.

To keep float values, use FloatTensor (float32) or DoubleTensor (float64) instead.
