pytorch torch.from_numpy()(从numpy数组创建一个张量,数组和张量共享相同内存)
生活随笔
收集整理的這篇文章主要介紹了
pytorch torch.from_numpy()(从numpy数组创建一个张量,数组和张量共享相同内存)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
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創(chuàng)建一個張量。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共享相同的內(nèi)存。 對張量的修改將反映在ndarray中,反之亦然。 返回的張量不可調(diào)整大小。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])總結(jié)
以上是生活随笔為你收集整理的pytorch torch.from_numpy()(从numpy数组创建一个张量,数组和张量共享相同内存)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: numpy.ndarray.view()
- 下一篇: pytorch torch.Tensor