numpy.random——Simple random data

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

Random values in a given shape.

Create an array of the given shape and populate it with random samples from a uniform distribution(均匀分布) over [0, 1).

'''
Parameters: d0, d1, ..., dn : int, optional
        The dimensions of the returned array, should all be positive. If no argument is given a single Python float is returned.

Returns: out : ndarray, shape (d0, d1, ..., dn)
        Random values.
'''

import numpy as np

a = np.random.rand()        # a = 0.06127240321484284
b = np.random.rand(1)       # b = [ 0.41584465], b.shape=(1,)
c = np.random.rand(2)       # c = [ 0.77530365  0.69171108]
d = np.random.rand(2,1)
'''
d = 
[[ 0.96921955]
 [ 0.06063684]]
'''
e = np.random.rand(1,2)     # e = [[ 0.83303266  0.15216985]]

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

Return a sample (or samples) from the “standard normal” distribution(“标准正态”分布).

If positive, int_like or int-convertible arguments are provided, randn generates an array of shape (d0, d1, …, dn), filled with random floats sampled from a univariate “normal” (Gaussian) distribution of mean 0 and variance 1 (if any of the d_i are floats, they are first converted to integers by truncation). A single float randomly sampled from the distribution is returned if no argument is provided.

This is a convenience function(便利函数). If you want an interface that takes a tuple as the first argument, use numpy.random.standard_normal instead.

'''
Parameters: 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.

Returns: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.

Notes:
For random samples from N(\mu, \sigma^2), use:
    sigma * np.random.randn(...) + mu
'''

import numpy as np

a = np.random.randn()       # a=-1.3911873244822348
b = np.random.randn(1)      # b=[-0.19737295]
c = np.random.randn(2)      # c=[ 0.94147094 -1.41735681]
d = np.random.randn(2,1)
'''
d=
[[ 0.56281246]
 [ 1.33878953]]
'''
e = np.random.randn(1,2)    # e=[[-0.50389743 -1.69531897]]
Notes:
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],  
       [ 0.39924804,  4.68456316,  4.99394529,  4.84057254]]) 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值