gistfile1.txt
arrays = [np.random.randn(3, 4) for _ in range(10)] # numpy.random.randn(d0, d1, …, dn)是从标准正态分布中返回一个或多个样本值
# [array([[ 1.3519317 , -0.68212026, 0.96451018, 0.69251565],
[-0.62524181, 1.45046706, -0.57531883, -0.37767839],
[-1.27988484, -1.43125495, 0.07252233, -1.13427989]]), array([[-0.72603421, 0.2683656 , -0.64769635, -0.89895735],
[-0.58840381, 2.56614425, 0.30928596, 1.00507638],
[ 0.1332985 , 1.14973477, 0.50649513, -1.30255904]]), array([[ 0.07806495, 0.2387269 , 0.01831128, -1.39705307],
[-0.69556098, -0.01114884, 0.59296978, -1.45320668],
[ 1.58638154, -0.06898421, -0.70581299, 0.49185596]]), array([[ 0.65397942, -1.78538761, 0.68226094, -0.75690177],
[-0.35950914, -0.83189441, 0.97711514, -0.95743309],
[ 1.22605178, 0.82011051, -0.29347015, -0.24006806]]), array([[-0.97076652, -1.35151969, -2.02388788, 1.00743087],
[-0.50052255, 1.63952628, -1.47138632, -0.34689022],
[ 0.52828345, -1.34262342, -0.01157388, 0.9277419 ]]), array([[ 0.81442876, -1.2498758 , -0.26470303, -0.0978072 ],
[-2.26048377, -1.55404892, -1.7753938 , 1.43983604],
[ 2.72650042, -0.61500847, -0.71959027, 1.44266012]]), array([[-0.76041601, 0.99546185, 0.26975875, -1.55711683],
[ 1.27798993, -0.61302248, 2.32101918, 1.92373527],
[ 0.63162727, -1.96330187, -1.40114865, 0.01390009]]), array([[ 0.69761018, -0.9639256 , -0.22771349, 1.67452061],
[ 0.78415725, -1.69689196, -1.17523483, -0.49991448],
[-0.57308436, -0.41904242, -0.32476675, -0.1082445 ]]), array([[-0.94143806, -0.71647054, 0.11011968, -0.32098219],
[-1.2197335 , 0.59615025, 0.12213161, 0.64346554],
[-1.85691632, 1.14845753, -1.21452606, -0.0432521 ]]), array([[-0.15754905, 0.72425403, -0.7734924 , -0.20817792],
[ 2.35616341, -0.06184002, -0.66127322, 1.89989309],
[ 2.71518784, -0.9749593 , -0.18803183, -0.02674294]])]
numpy.random.randn(d0, d1, ..., dn)
# d0, d1, ..., dn : int, optional The dimensions of the returned array, should be all positive. If no argument is given a single Python float is returned.
# Z : ndarray or float A (d0, d1, ..., dn)-shaped array of floating-point samples from the standard normal distribution, or a single such float if no parameters were supplied
# For random samples from N(\mu, \sigma^2), use:
sigma * np.random.randn(...) + mu
# Two-by-four array of samples from N(3, 6.25)
2.5 * np.random.randn(2, 4) + 3
# array([[-4.49401501, 4.00950034, -1.81814867, 7.29718677], #random
[ 0.39924804, 4.68456316, 4.99394529, 4.84057254]]) #random
# 随机数矩阵的产生后 往往伴随着算维度 和 重整维度
print str(arrays)+'\n'+str(np.stack(arrays, axis=0).shape)
[array([[ 1.3519317 , -0.68212026, 0.96451018, 0.69251565],
[-0.62524181, 1.45046706, -0.57531883, -0.37767839],
[-1.27988484, -1.43125495, 0.07252233, -1.13427989]]), array([[-0.72603421, 0.2683656 , -0.64769635, -0.89895735],
[-0.58840381, 2.56614425, 0.30928596, 1.00507638],
[ 0.1332985 , 1.14973477, 0.50649513, -1.30255904]]), array([[ 0.07806495, 0.2387269 , 0.01831128, -1.39705307],
[-0.69556098, -0.01114884, 0.59296978, -1.45320668],
[ 1.58638154, -0.06898421, -0.70581299, 0.49185596]]), array([[ 0.65397942, -1.78538761, 0.68226094, -0.75690177],
[-0.35950914, -0.83189441, 0.97711514, -0.95743309],
[ 1.22605178, 0.82011051, -0.29347015, -0.24006806]]), array([[-0.97076652, -1.35151969, -2.02388788, 1.00743087],
[-0.50052255, 1.63952628, -1.47138632, -0.34689022],
[ 0.52828345, -1.34262342, -0.01157388, 0.9277419 ]]), array([[ 0.81442876, -1.2498758 , -0.26470303, -0.0978072 ],
[-2.26048377, -1.55404892, -1.7753938 , 1.43983604],
[ 2.72650042, -0.61500847, -0.71959027, 1.44266012]]), array([[-0.76041601, 0.99546185, 0.26975875, -1.55711683],
[ 1.27798993, -0.61302248, 2.32101918, 1.92373527],
[ 0.63162727, -1.96330187, -1.40114865, 0.01390009]]), array([[ 0.69761018, -0.9639256 , -0.22771349, 1.67452061],
[ 0.78415725, -1.69689196, -1.17523483, -0.49991448],
[-0.57308436, -0.41904242, -0.32476675, -0.1082445 ]]), array([[-0.94143806, -0.71647054, 0.11011968, -0.32098219],
[-1.2197335 , 0.59615025, 0.12213161, 0.64346554],
[-1.85691632, 1.14845753, -1.21452606, -0.0432521 ]]), array([[-0.15754905, 0.72425403, -0.7734924 , -0.20817792],
[ 2.35616341, -0.06184002, -0.66127322, 1.89989309],
[ 2.71518784, -0.9749593 , -0.18803183, -0.02674294]])]
(10, 3, 4)
np.stack(arrays, axis=1)
array([[[ 1.3519317 , -0.68212026, 0.96451018, 0.69251565],
[-0.72603421, 0.2683656 , -0.64769635, -0.89895735],
[ 0.07806495, 0.2387269 , 0.01831128, -1.39705307],
[ 0.65397942, -1.78538761, 0.68226094, -0.75690177],
[-0.97076652, -1.35151969, -2.02388788, 1.00743087],
[ 0.81442876, -1.2498758 , -0.26470303, -0.0978072 ],
[-0.76041601, 0.99546185, 0.26975875, -1.55711683],
[ 0.69761018, -0.9639256 , -0.22771349, 1.67452061],
[-0.94143806, -0.71647054, 0.11011968, -0.32098219],
[-0.15754905, 0.72425403, -0.7734924 , -0.20817792]],
[[-0.62524181, 1.45046706, -0.57531883, -0.37767839],
[-0.58840381, 2.56614425, 0.30928596, 1.00507638],
[-0.69556098, -0.01114884, 0.59296978, -1.45320668],
[-0.35950914, -0.83189441, 0.97711514, -0.95743309],
[-0.50052255, 1.63952628, -1.47138632, -0.34689022],
[-2.26048377, -1.55404892, -1.7753938 , 1.43983604],
[ 1.27798993, -0.61302248, 2.32101918, 1.92373527],
[ 0.78415725, -1.69689196, -1.17523483, -0.49991448],
[-1.2197335 , 0.59615025, 0.12213161, 0.64346554],
[ 2.35616341, -0.06184002, -0.66127322, 1.89989309]],
[[-1.27988484, -1.43125495, 0.07252233, -1.13427989],
[ 0.1332985 , 1.14973477, 0.50649513, -1.30255904],
[ 1.58638154, -0.06898421, -0.70581299, 0.49185596],
[ 1.22605178, 0.82011051, -0.29347015, -0.24006806],
[ 0.52828345, -1.34262342, -0.01157388, 0.9277419 ],
[ 2.72650042, -0.61500847, -0.71959027, 1.44266012],
[ 0.63162727, -1.96330187, -1.40114865, 0.01390009],
[-0.57308436, -0.41904242, -0.32476675, -0.1082445 ],
[-1.85691632, 1.14845753, -1.21452606, -0.0432521 ],
[ 2.71518784, -0.9749593 , -0.18803183, -0.02674294]]])
random.random random.random()用于生成一个0到1的随机符点数: 0 <= n < 1.0
random.uniform random.uniform的函数原型为:random.uniform(a, b),用于生成一个指定范围内的随机符点数,两个参数其中一个是上限,一个是下限。如果a > b,则生成的随机数n: a <= n <= b。如果 a