https://pytorch.org/docs/1.1.0/torch.html?highlight=numpy#torch.from_numpy
torch.from_numpy(ndarray) → Tensor
Creates a Tensor from a numpy.ndarray.
从numpy.ndarray创建一个张量。
The returned tensor and ndarray share the same memory. Modifications to the tensor will be reflected in the ndarray and vice versa. The returned tensor is not resizable.
返回的张量和ndarray共享相同的内存。
对张量的修改将反映在ndarray中,反之亦然。 返回的张量不可调整大小。
Example:
>>> a = numpy.array([1, 2, 3])
>>> t = torch.from_numpy(a)
>>> t
tensor([ 1, 2, 3])
>>> t[0] = -1
>>> a
array([-1, 2, 3])