numpy的函数入门:numpy.random.randint;numpy.squeeze();numpy数组转化为cv图片

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)

得到的输出如下图:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值