np.random.rand()

np.random.rand()可以返回任意纬度的矩阵,矩阵内的数值为[0,1)的随机数

np.random.rand(d0,d1,…,dn)

d0~dn:为输出矩阵的纬度

例如:

>>> np.random.rand(2,3)
array([[0.48290715, 0.35586919, 0.82244376],
       [0.72144442, 0.52671832, 0.25967954]])
>>> np.random.rand(4,3,2)
array([[[0.04365607, 0.09989154],
        [0.29794552, 0.40393603],
        [0.13601166, 0.52009022]],

       [[0.61301835, 0.92477563],
        [0.23488518, 0.24992936],
        [0.0665239 , 0.42134488]],

       [[0.03398788, 0.50690946],
        [0.30294694, 0.65442827],
        [0.11361693, 0.61128644]],

       [[0.67004488, 0.67306076],
        [0.19438974, 0.14208858],
        [0.93978535, 0.39877183]]])

np.random.randn()

np.random.randn()和np.random.rand()非常相似,同样可以获得任意纬度的矩阵,只是返回矩阵内的数值为符合均值为0、标准差为1的正态分布.

np.random.randn(d0,d1,…,dn)

d0~dn:为输出矩阵的纬度

>>> np.random.randn(2,3)
array([[-0.13906226, -0.0093422 , -0.16018623],
       [-1.61093869,  0.92672041, -1.07908674]])
>>> np.random.randn(4,3,2)
array([[[-0.47225703, -0.51533159],
        [ 0.07488023, -0.10368794],
        [ 0.8739207 , -0.4209093 ]],

       [[ 0.52181307,  0.23516168],
        [-0.11051864, -0.30658818],
        [ 1.10396061, -0.20688803]],

       [[-1.70228738,  0.40502851],
        [ 2.34587959, -0.51460201],
        [-0.78227885, -0.60468352]],

       [[ 1.70129296,  1.37562914],
        [ 1.38122835, -0.72530221],
        [ 1.57112625, -0.36154434]]])
posted @ 2018-05-12 11:44:40
评论加载中...

发表评论