當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python mxnet.ndarray.random.randn用法及代碼示例

用法:

mxnet.ndarray.random.randn(*shape, **kwargs)

參數

  • loc(float or NDArray) - 分布的平均值(中心)。
  • scale(float or NDArray) - 分布的標準偏差(分布或寬度)。
  • shape(int or tuple of ints) - 要繪製的樣本數。如果形狀是,例如,(m, n)locscale是標量,輸出形狀將是(m, n).如果locscale是具有形狀的 NDArray,例如,(x, y),則輸出將具有形狀(x, y, m, n),其中m*n為每個抽取樣本[loc, scale)一對。
  • dtype({'float16', 'float32', 'float64'}) - 輸出樣本的數據類型。默認為‘float32’
  • ctx(mxnet.context.Context) - 輸出的設備上下文。默認為當前上下文。被覆蓋loc.contextloc是一個 NDArray。
  • out(NDArray) - 將輸出存儲到現有的 NDArray。

返回

如果輸入 shape 具有形狀,例如 (m, n)locscale 是標量,則輸出形狀將為 (m, n) 。如果 locscale 是具有形狀的 NDArray,例如 (x, y) ,則輸出將具有形狀 (x, y, m, n) ,其中為每個 [loc, scale) 對繪製 m*n 樣本。

返回類型

ND陣列

從正態(高斯)分布中抽取隨機樣本。

樣本根據由loc(均值)和scale(標準差)參數化的正態分布分布。

例子

>>> mx.nd.random.randn()
2.21220636
<NDArray 1 @cpu(0)>
>>> mx.nd.random.randn(2, 2)
[[-1.856082   -1.9768796 ]
[-0.20801921  0.2444218 ]]
<NDArray 2x2 @cpu(0)>
>>> mx.nd.random.randn(2, 3, loc=5, scale=1)
[[4.19962   4.8311777 5.936328 ]
[5.357444  5.7793283 3.9896927]]
<NDArray 2x3 @cpu(0)>

相關用法


注:本文由純淨天空篩選整理自apache.org大神的英文原創作品 mxnet.ndarray.random.randn。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。