np.random.random 使用法

numpy.random.random

numpy.random. random ( size=None )

Return random floats in the half-open interval [0.0, 1.0).

Results are from the “continuous uniform” distribution over thestated interval. To sample Unif[a, b), b > a multiplythe output of random_sample by (b-a) and add a:

(b - a) * random_sample() + a
Parameters:

size : int or tuple of ints, optional

Output shape. If the given shape is, e.g., (m, n, k), thenm * n * k samples are drawn. Default is None, in which case asingle value is returned.

Returns:

out : float or ndarray of floats

Array of random floats of shape size (unless size=None, in whichcase a single float is returned).

Examples

>>> np.random.random_sample()#返回一个随机数
0.47108547995356098
>>> type(np.random.random_sample())
<type 'float'>
>>> np.random.random_sample((5,))#一次返回五个随机数
array([ 0.30220482,  0.86820401,  0.1654503 ,  0.11659149,  0.54323428])

Three-by-two array of random numbers from [-5, 0):

>>> 5 * np.random.random_sample((3, 2)) - 5#一次返回一个随机数矩阵
array([[-3.99149989, -0.52338984],
       [-2.99091858, -0.79479508],
       [-1.23204345, -1.75224494]])
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值