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

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

pytorch常用函數(shù)之torch.randn()解讀_python

作者:土豆豆豆豆豆 ? 更新時間: 2023-04-01 編程語言

pytorch常用函數(shù)torch.randn()

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

功能:從標(biāo)準(zhǔn)正態(tài)分布(均值為0,方差為1)中抽取的一組隨機(jī)數(shù)。返回一個張量

  • sizes (int…) - 整數(shù)序列,定義輸出張量的形狀
  • out (Tensor, optinal) - 結(jié)果張量

eg:

random = torch.randn(2, 3)
out: ?0.5419 0.1594 -0.0413
? ? ? ? -2.7937 0.9534 0.4561

pytorch torch.chunk(tensor, chunks, dim)

說明:在給定的維度上講張量進(jìn)行分塊。

參數(shù):

  • tensor(Tensor) -- 待分塊的輸入張量
  • chunks(int) -- 分塊的個數(shù)
  • dim(int) -- 維度,沿著此維度進(jìn)行分塊
>>> x = torch.randn(3, 3)
>>> x
tensor([[ 1.0103, ?2.3358, -1.9236],
? ? ? ? [-0.3890, ?0.6594, ?0.6664],
? ? ? ? [ 0.5240, -1.4193, ?0.1681]])
>>> torch.chunk(x, 3, dim=0)
(tensor([[ 1.0103, ?2.3358, -1.9236]]), tensor([[-0.3890, ?0.6594, ?0.6664]]), tensor([[ 0.5240, -1.4193, ?0.1681]]))
>>> torch.chunk(x, 3, dim=1)
(tensor([[ 1.0103],
? ? ? ? [-0.3890],
? ? ? ? [ 0.5240]]), tensor([[ 2.3358],
? ? ? ? [ 0.6594],
? ? ? ? [-1.4193]]), tensor([[-1.9236],
? ? ? ? [ 0.6664],
? ? ? ? [ 0.1681]]))
>>> torch.chunk(x, 2, dim=1)
(tensor([[ 1.0103, ?2.3358],
? ? ? ? [-0.3890, ?0.6594],
? ? ? ? [ 0.5240, -1.4193]]), tensor([[-1.9236],
? ? ? ? [ 0.6664],
? ? ? ? [ 0.1681]]))

總結(jié)

原文鏈接:https://blog.csdn.net/JannyYang/article/details/100514037

欄目分類
最近更新