pytorch.range()和pytorch.arange()的區(qū)別及說明
更新時間:2023年08月03日 14:28:37 作者:小餅干超人
這篇文章主要介紹了pytorch.range()和pytorch.arange()的區(qū)別及說明,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
pytorch.range()和pytorch.arange()的區(qū)別
>>> y=torch.range(1,6) >>> y tensor([1., 2., 3., 4., 5., 6.]) >>> y.dtype torch.float32 >>> z=torch.arange(1,6) >>> z tensor([1, 2, 3, 4, 5]) >>> z.dtype torch.int64
心得
torch.range(start=1, end=6)的結(jié)果是會包含end的,而torch.arange(start=1, end=6)的結(jié)果并不包含end。- 兩者創(chuàng)建的
tensor的類型也不一樣。
參考:
Pytorch torch.range()&torch.arange()
torch.range(start=1, end=6)
結(jié)果是會包含end的,創(chuàng)建的tensor的類型為float32。
torch.arange(start=1, end=6)
結(jié)果并不包含end,創(chuàng)建的tensor的類型為int64。
代碼
>>> y=torch.range(1,6) >>> y tensor([1., 2., 3., 4., 5., 6.]) >>> y.dtype torch.float32 >>> z=torch.arange(1,6) >>> z tensor([1, 2, 3, 4, 5]) >>> z.dtype torch.int64
pytorch torch.arange
應(yīng)用
>>> torch.arange(5) tensor([ 0, 1, 2, 3, 4])
API
torch.arange(start=0, end, step=1, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor
| 參數(shù) | 描述 |
|---|---|
| start (Number) | |
| end (Number) | |
| step (Number) | |
| out (Tensor, optional) | |
| dtype (torch.dtype, optional) | |
| layout (torch.layout, optional) | |
| device (torch.device, optional) | |
| requires_grad (bool, optional) |
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- PyTorch中torch.load()的用法和應(yīng)用
- python中torch.load中的map_location參數(shù)使用
- Pytorch中的torch.nn.Linear()方法用法解讀
- Pytorch中的torch.where函數(shù)使用
- python中的List sort()與torch.sort()
- 關(guān)于torch.scatter與torch_scatter庫的使用整理
- PyTorch函數(shù)torch.cat與torch.stac的區(qū)別小結(jié)
- 使用with torch.no_grad():顯著減少測試時顯存占用
- PyTorch中torch.save()的用法和應(yīng)用小結(jié)
相關(guān)文章
Django JSonResponse對象的實現(xiàn)
本文主要介紹了Django JSonResponse對象的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-03-03
基于Python實現(xiàn)報表自動化并發(fā)送到郵箱
作為數(shù)據(jù)分析師,我們需要經(jīng)常制作統(tǒng)計分析圖表。但是報表太多的時候往往需要花費我們大部分時間去制作報表。本文將利用Python實現(xiàn)報表自動化并發(fā)送到郵箱,需要的可以參考一下2022-07-07
Django ORM數(shù)據(jù)庫操作處理全面指南
本文深度探討Django ORM的概念、基礎(chǔ)使用、進階操作以及詳細解析在實際使用中如何處理數(shù)據(jù)庫操作,同時,我們還討論了模型深入理解,如何進行CRUD操作,并且深化理解到數(shù)據(jù)庫遷移等高級主題2023-09-09
pandas DataFrame.shift()函數(shù)的具體使用
本文主要介紹了pandas DataFrame.shift()函數(shù)的使用,pandas DataFrame.shift()函數(shù)可以把數(shù)據(jù)移動指定的位數(shù),有需要了解pandas DataFrame.shift()用法的朋友可以參考一下2021-05-05

