Numpy的函数入门:numpy.random.randint;numpy.squeeze;numpy数组转化为cv图片
numpy的函数
numpy.random.randint(low, high=None, size=None, dtype=‘l’)
返回一个随机整型数,[low, high)。
high:int类型。
low:int类型。如果high=None,则返回[0,low)的值。如果high有取值,则返回[low, high)的值。
size: int类型或由int类型的数据组成的数组。输出随机数的尺寸,默认是None的,仅仅返回满足要求的单一随机数。
dtype:输出的格式。
numpy.squeeze()
把张量中维度为1的维度去掉
import numpy as np
n_dim_data = np.random.rand(10,1,10,1,1)
n_dim_squeeze = np.squeeze(n_dim_data)
print(n_dim_data.shape) ## (10,1,10,1,1)
print(n_dim_squeeze.shape) ## (10,10)
numpy数组转化为cv图片
>>> import numpy as np
>>> import cv2
>>> b = np.random.randint(0,255,(200,300),dtype=np.uint8)
>>> g = np.random.randint(0,255,(200,300),dtype=np.uint8)
>>> r = np.random.randint(0,255,(200,300),dtype=np.uint8)
>>> img = cv2.merge([b,g,r])
>>> cv2.imshow('1',img)
>>> cv2.waitKey(0)
得到的输出如下图: