python numpy.random.uniform函数

函数: numpy.random.uniform(low,high,size)

Draw samples from a uniform distribution.
Samples are uniformly distributed over the half-open interval
            ----------
            low : float or array_like of floats, optional
                Lower boundary of the output interval.  All values generated will be
                greater than or equal to low.  The default value is 0.
            high : float or array_like of floats
                Upper boundary of the output interval.  All values generated will be
                less than or equal to high.  The default value is 1.0.
            size : int or tuple of ints, optional
                Output shape.  If the given shape is, e.g., ``(m, n, k)``, then
                ``m * n * k`` samples are drawn.  If size is ``None`` (default),
                a single value is returned if ``low`` and ``high`` are both scalars.
                Otherwise, ``np.broadcast(low, high).size`` samples are drawn.
    
            Returns
            -------

功能:从一个均匀分布[low,high)中随机采样,采样数量为size。注意定义域是左闭右开,即包含low,不包含high。
参数介绍:
(1) low: 采样下界,float类型,默认值为0。
(2) high: 采样上界,float类型,默认值为1。
(3) size: 输出样本数目,为int或元组(tuple)类型,例如,size=(m,n,k), 则输出m n k个样本。缺省时输出1个值。
(4) 返回值:numpy ndarray类型,其形状和参数size中描述一致。
举例:

import numpy as np
a = np.random.uniform()
b = np.random.uniform(1, 3, 5)
c = np.random.uniform(7, 10, (2, 3))
print(
    'a=', a,
    '\nb=', b,
    '\nc=', c,
)

得到输出:

a= 0.37237035830791587 
b= [1.99963941 1.27452227 2.54252202 2.68460081 1.04137335] 
c= [[7.81326369 8.62565301 8.48519219]
 [9.27817572 8.47892165 9.83586147]]
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值