Python-基础

1.关于读图片

1.
img = Image.open('root')
img.save('../test.jpg')
img.show() # 显示图片
2.
img=cv2.imread('root')
plt.imshow(img,‘brg’)
pylab.show()
cv2.imwrite('root', img)


2.字符分割

string = '1_A.jpg'
a =  string.split('_')[0]
b = string.split('_')[1]

3.numpy <--> tensor

tensor转换成numpy

a = torch.FloatTensor(2,9)
print a.numpy();

numpy转换成tensor

a = np.ones(10)
torch.from_numpy(a)

4.Variable <--> numpy

将Variable转换成numpy

import torch
from torch.autograd import Variable

a = Variable(torch.FloatTensor(2,5))
print a.data.numpy()

将numpy转换为Variable

import torch
import numpy as np
from torch.autograd import Variable

a = np.ones(10)
print Variable(torch.from_numpy(a))





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值