PyTorch Tensor to NumPy Array and Back - Sparrow Computing
https://sparrow.dev/pytorch-numpy-conversion22.03.2021 · PyTorch is designed to be pretty compatible with NumPy. Because of this, converting a NumPy array to a PyTorch tensor is simple: import torch import numpy as np x = np.eye (3) torch.from_numpy (x) # Expected result # tensor ( [ [1., 0., 0.], # [0., 1., 0.], # [0., 0., 1.]], dtype=torch.float64)