python random模块中seed函数的详解_numpy.random模块常用函数解析

numpy.random模块中常用函数解析

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

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

按照给定形状产生一个多维数组,每个元素在0到1之间

注意: 这里定义数组形状时,不能采用tuple

import numpy as np

np.random.rand(2, 3)

array([[ 0.44590044, 0.36234046, 0.51609462],

[ 0.45733218, 0.80836224, 0.31628453]])

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

generates an array of shape (d0, d1, ..., dn), filled with random floats sampled from a univariate “normal” distribution of mean 0 and variance 1

按照给定形状产生一个多维数组,数组中的元素服从标准正态分布

若要产生服从N(mu, sigma^2)分布的样本, 使用sigma * np.random.randn(...) + mu

例如产生 2 * 4 samples from N(3, 6.25):

2.5 * np.random.randn(2, 4) + 3

array([[ 2.90478558, 6.05670578, 6.21539068, 3.3955507 ],

[ 0.11594363, 3.17433693, 5.35625762, 1.4824643 ]])

3. numpy.random.randint(low, high=None, size=None, dtype='l')

Return random integers from low (inclusive) to high (exclusive).

按照给定的形状和范围产生随机整数

np.random.randint(0, 10, size=(2, 4))

array([[2, 7, 2, 1],

[3, 2, 4, 1]])

4. numpy.random.random_integers(

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值