numpy random 生成随机矩阵

import numpy as np

np.random.rand(a, b)

>>> np.random.rand(4,3)
array([[ 0.06679473,  0.71073515,  0.5694172 ],
       [ 0.95018143,  0.60161401,  0.8076899 ],
       [ 0.40341822,  0.72154255,  0.92283012],
       [ 0.81143322,  0.87853742,  0.38013707]])

np.random.randint(a, b, size=(c, d)):

>>> np.random.randint(0,10,(4,3))
array([[1, 9, 5],
       [6, 1, 1],
       [8, 2, 0],
       [3, 4, 3]])

 

二项分布函数

np.random.binomial(n,p,size=N),函数的返回值表示n中成功的次数,且以Cn^x*p^x*(1-p)^(n-x)的概率选择成功x次

>>> np.random.binomial(5, 0.5, size=(2,3)) # 一次试验抛5次硬币朝上的硬币数,做2*3次试验
array([[3, 2, 5],
       [2, 2, 3]])
原文地址:https://www.cnblogs.com/cymwill/p/8489342.html