Python图像处理常用代码,numpy教程

这里的代码是截取的我的代码片段,或许难以阅读,有不理解的地方欢迎交流生成空列表及末尾添加x=[]x.append(img_path[j])字符串连接img_path=get_imlist('D:\\CK\\'+str(i)) #字符串连接图像矩阵和一维数组转化 img_ndarray=numpy.asarray(img,dtype='float64')/256 #将图像转化为数组并
摘要由CSDN通过智能技术生成

这里的代码是截取的我的代码片段,或许难以阅读,有不理解的地方欢迎交流


  • 生成空列表及末尾添加
x=[]
x.append(img_path[j])
  • 图像矩阵和一维数组转化
img_ndarray=numpy.asarray(img,dtype='float64')/256  #将图像转化为数组并将像素转化到0-1之间
data[d-1]=numpy.ndarray.flatten(img_ndarray)    #将图像的矩阵形式转化为一维数组保存到data中
  • 将矩阵中浮点数转化为int类型
data_label=data_label.astype(numpy.int)  #将标签转化为int类型
  • Python生成一个范围内的随机整数。其中参数a是下限,参数b是上限
print random.randint(12, 20) #生成的随机数n: 12 <= n <= 20

numpy教程

y = 2.5
print type(y) # 输出 "<type 'float'>"
print y ** 2 # 输出 "6.25"
#Python中没有 x++ 和 x-- 的操作符。

#布尔型:Python用英语实现了所有的布尔逻辑,而不是操作符(&&和||等)。
t = True
f = False
print type(t) # 输出 "<type 'bool'>"
print t and f # 逻辑与 AND; prints "False"
print t or f  # 逻辑或 OR; prints "True"
print not t   # 逻辑非 NOT; prints "False"
print t != f  # 逻辑异或 XOR; prints "True"  

#字符串:Python对字符串的支持非常棒。
hello = 'hello'   # 字符串可以用单引号,也可以用双引号
world = "world"   
print hello       # Prints "hello"
print len(hello)  # 字符串长度 prints "5"
hw = hello + ' ' + world  # 字符串连接
print hw  # prints "hello world"
hw12 = '%s %s %d' % (hello, world, 12)  # 格式化输出
print hw12  # prints "hello world 12"

#字符串对象有一系列有用的方法,比如:
s = "hello"
print s.capitalize() 
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值