日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

PyTorch随笔-2

發布時間:2025/3/12 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PyTorch随笔-2 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

torch.Tensor 是torch.FloatTensor的別名。
tensor可用Python list或sequence 使用torch.tensor()進行構造。

import torch x=torch.tensor([[10,20],[2,4]]) print(x) tensor([[10, 20],[ 2, 4]]) import torch a=[[10.2,20.6],[2,4]] x=torch.DoubleTensor(a) print(x) y=torch.IntTensor(a) print(y) tensor([[10.2000, 20.6000],[ 2.0000, 4.0000]], dtype=torch.float64) tensor([[10, 20],[ 2, 4]], dtype=torch.int32) <ipython-input-14-f9db31b67daa>:5: DeprecationWarning: an integer is required (got type float). Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.y=torch.IntTensor(a)

torch.tensor()始終復制數據。如果您有一個 Tensor數據,并且只想更改它的requires_grad標志,可使用requires_grad_()或 detach() 防止拷貝。
如果您有一個numpy數組并希望避免復制 ,可使用torch.as_tensor()。

import torch import numpy as np a = np.arange(8) b = a.reshape(4,2) print (b) y=torch.torch.as_tensor(b) print(y) y[1][1]=55 print(y) print(b) [[0 1][2 3][4 5][6 7]] tensor([[0, 1],[2, 3],[4, 5],[6, 7]]) tensor([[ 0, 1],[ 2, 55],[ 4, 5],[ 6, 7]]) [[ 0 1][ 2 55][ 4 5][ 6 7]] import torch y=torch.zeros([2, 4], dtype=torch.int32) print(y) tensor([[0, 0, 0, 0],[0, 0, 0, 0]], dtype=torch.int32)

總結

以上是生活随笔為你收集整理的PyTorch随笔-2的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。