A Numpy array can be converted into a tensor using one of the following methods of the torch.
Here is an example:
>>> import numpy as np>>> import torch>>> a=np.array([1,2,3,4])>>> aarray([1, 2, 3, 4])>>> f=torch.tensor(a)>>> ftensor([1, 2, 3, 4])>>> f=torch.from_numpy(a)>>> ftensor([1, 2, 3, 4])>>> f=torch.as_tensor(a)>>> ftensor([1, 2, 3, 4])