日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Pytorch基礎之torch.randperm的使用_python

作者:gy笨瓜 ? 更新時間: 2023-04-01 編程語言

Pytorch torch.randperm的使用

torch.randperm(n):將0~n-1(包括0和n-1)隨機打亂后獲得的數字序列,函數名是random permutation縮寫

【sample】

? ? ? ? ?torch.randperm(10)
===> tensor([2, 3, 6, 7, 8, 9, 1, 5, 0, 4])

torch.randn和torch.rand有什么區別

torch.rand和torch.randn有什么區別? y = torch.rand(5,3) y=torch.randn(5,3)

一個均勻分布,一個是標準正態分布。

均勻分布

torch.rand(*sizes, out=None) → Tensor

返回一個張量,包含了從區間[0, 1)的均勻分布中抽取的一組隨機數。張量的形狀由參數sizes定義。

參數:

  • sizes (int...) - 整數序列,定義了輸出張量的形狀
  • out (Tensor, optinal) - 結果張量

例子:

torch.rand(2, 3)
0.0836 0.6151 0.6958
0.6998 0.2560 0.0139
[torch.FloatTensor of size 2x3]

標準正態分布

torch.randn(*sizes, out=None) → Tensor

返回一個張量,包含了從標準正態分布(均值為0,方差為1,即高斯白噪聲)中抽取的一組隨機數。張量的形狀由參數sizes定義。

參數:

  • sizes (int...) - 整數序列,定義了輸出張量的形狀
  • out (Tensor, optinal) - 結果張量

例子:

torch.randn(2, 3)
0.5419 0.1594 -0.0413
-2.7937 0.9534 0.4561
[torch.FloatTensor of size 2x3]

?其他:

離散正態分布

torch.normal(means, std, out=None) → → Tensor

線性間距向量

torch.linspace(start, end, steps=100, out=None) → Tensor

返回一個1維張量,包含在區間start和end上均勻間隔的step個點。

輸出張量的長度由steps決定。

總結

原文鏈接:https://blog.csdn.net/u012633319/article/details/109039499

欄目分類
最近更新