NumPy数组创建(random模块创建)

熟悉ndarray创建的不同方式(扩展补充):

      至于常用的一些创建方式,在这篇博文中已经写过,这次主要是对用random创建进行补充

1. rand

查看帮助文档: (部分)

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

理解:
可以给rand传入n个参数,最终得出n维数组,n只允许传入int型,返回的数组中的数字大小范围是 [0,1) 注意区间

例如:
randdom.rand

2. randn

查看帮助文档:(部分)

Return a sample (or samples) from the "standard normal" distribution.

理解:
可以传多参数,返回一个或一组样本具有正态分布

例如:
random.randn

3. randint

查看帮助文档:(部分)

randint(low, high=None, size=None, dtype='l')
    
    Return random integers from `low` (inclusive) to `high` (exclusive).
    
    Return random integers from the "discrete uniform" distribution of
    the specified dtype in the "half-open" interval [`low`, `high`). If
    `high` is None (the default), then results are from [0, `low`).

理解:
可以传三参数:low(默认0)、high(默认None)、size(默认None),最后生成在半开半闭区间[low,high)上离散均匀分布的整数值;若high=None,则取值区间变为[0,low) 注意区间

例如:
在这里插入图片描述

4. random_integer

查看帮助文档:(部分)

random_integers(...) method of mtrand.RandomState instance
    random_integers(low, high=None, size=None)
    
    Random integers of type np.int between `low` and `high`, inclusive.
    
    Return random integers of type np.int from the "discrete uniform"
    distribution in the closed interval [`low`, `high`].  If `high` is
    None (the default), then results are from [1, `low`]. The np.int
    type translates to the C long type used by Python 2 for "short"
    integers and its precision is platform dependent.

理解:
可以传三参数:low(默认0)、high(默认None)、size(默认None),最后生成闭区间[low,high]上离散均匀分布的整数值;若high=None,则取值区间变为[1,low] 注意区间

例如:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值