numpy中有一些常用的用来产生随机数的函数: randn()和rand()。
numpy.random.randn(d0, d1, …, dn)是从标准正态分布中返回一个或多个样本值。
numpy.random.rand(d0, d1, …, dn)的随机样本位于[0, 1)之间。
import numpy as np
arr1 = np.random.randn(3,4)
print(arr1)
print('..............................................')
arr2 = np.random.rand(3,4)
print(arr2)
2、numpy.random.randint(low, high=None, size=None, dtype=‘l’)
low: int
生成的数值最低要大于等于low。
(hign = None时,生成的数值要在[0, low)区间内)
high: int (可选)
如果使用这个值,则生成的数值在[low, high)区间。
size: int or tuple of ints(可选)
输出随机数的尺寸,比如size = (m * n* k)则输出同规模即m * n* k个随机数。默认是None的,仅仅返回满足要求的单一随机数。
dtype: dtype(可选):想要输出的格式。如int64、int等等
import cv2
import numpy as np
a = np.random.randint(12, size=(1,2))
print(a)
print(a.tostring())