Numpy库中的两个随机函数rand & randn
总结
| 类型 | 分布 |
|---|---|
| np.random.randn() | 正态分布 |
| np.random.rand() | 均匀分布 |
np.random.randn()
randn产生的随机数服从正态分布,即randn中的n对应normal distribution
# Generate random matrix with the shape of (3,2)
np.random.randn(3,2)

np.random.rand()
randn产生的随机数服从均匀分布
# Generate random matrix with the shape of (3,2)
np.random.rand(3,2)

本文介绍了Numpy库中的两个随机数生成函数:rand和randn。rand函数用于生成服从均匀分布的随机数,而randn则用于生成服从正态分布的随机数。例如,`np.random.rand(3,2)`将生成一个3x2的矩阵,其元素均匀分布于[0, 1)区间;`np.random.randn(3,2)`则会生成一个同样形状的矩阵,元素遵循标准正态分布。
959

被折叠的 条评论
为什么被折叠?



