numpy——random

本文详细介绍了NumPy中各种随机数生成函数的使用方法,包括rand、random、randn、randint和normal等,解释了它们如何生成不同分布的随机数,并提供了代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

函数含义
rand(*dn)Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).
random(arg)作用与rand差不多,得到的范围也是[0, 1),但这只能接受一个参数,可以是一个数字,也可以是一个tuple
randn(*dn)Return a sample (or samples) from the “standard normal” distribution.(得到是符合正态分布的随机数)*dn代表了要生成的是几维的
randint(low, high, size, dtype)在[low, high)之间,产生离散均匀分布的结果
normal(loc, scale, size)产生size个正态分布的结果,μ = loc, σ = scale
import numpy as np
print(np.random.rand(3, 4))
print()
print(np.random.random((3,4)))
print()
print(np.random.randn(3,4))
print()
print(np.random.randint(low=2, high=10, size=8))

rand(*dn)

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

random(arg)

randn(*dn)

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

randint(low, high, size, dtype)

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).

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值