numpy.random模块中常用函数解析
1. numpy.random.rand(d0, d1, ..., dn)
Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1)
按照给定形状产生一个多维数组,每个元素在0到1之间
注意: 这里定义数组形状时,不能采用tuple
import numpy as np
np.random.rand(2, 3)
array([[ 0.44590044, 0.36234046, 0.51609462],
[ 0.45733218, 0.80836224, 0.31628453]])
2. numpy.random.randn(d0, d1, ..., dn)
generates an array of shape (d0, d1, ..., dn), filled with random floats sampled from a univariate “normal” distribution of mean 0 and variance 1
按照给定形状产生一个多维数组,数组中的元素服从标准正态分布
若要产生服从N(mu, sigma^2)分布的样本, 使用sigma * np.random.randn(...) + mu
例如产生 2 * 4 samples from N(3, 6.25):
2.5 * np.random.randn(2, 4) + 3
array([[ 2.90478558, 6.05670578, 6.21539068, 3.3955507 ],
[ 0.11594363, 3.17433693, 5.35625762, 1.4824643 ]])
3. numpy.random.randint(low, high=None, size=None, dtype='l')
Return random integers from low (inclusive) to high (exclusive).
按照给定的形状和范围产生随机整数
np.random.randint(0, 10, size=(2, 4))
array([[2, 7, 2, 1],
[3, 2, 4, 1]])
4. numpy.random.random_integers(