![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
yee_0217
这个作者很懒,什么都没留下…
展开
-
Python之string和bytes的相互转化
1.string转bytess = 'hello world!' #'hello world!'#方法一b = bytes(s,encoding='utf8') #需要指定编码格式#方法二b=s.encode('utf8')2.bytes转string#b:b'hello world!'#方法一s = str(b,'utf8') #方法二s = b.decode...原创 2019-11-08 15:22:34 · 687 阅读 · 0 评论 -
python之numpy中的tile函数
Numpy的 tile() 函数,就是将原矩阵横向、纵向地复制。tile 是瓷砖的意思,顾名思义,这个函数就是把数组像瓷砖一样铺展开来。举个例子,原矩阵:mat = array([[1,2], [3, 4]])横向:tile(mat, (1, 4))# 等同于tile(mat, 4)结果:[[1 2 1 2 1 2 1 2] [3 4 3 4 3 ...转载 2019-10-30 11:20:33 · 202 阅读 · 0 评论 -
python中自带的translate模块
python提供了谷歌翻译的第三方包,可以实现多种语言之间的相互翻译。translate包的下载地址:https://pypi.org/project/translate/可以通过使用pip安装: pip install translate使用代码示例:# encoding: utf-8from translate import Translator# 以下是将简...原创 2019-08-26 15:30:42 · 11009 阅读 · 7 评论 -
python之csv文件转化为tsv文件
不需要导入任何库:csv和tsv的区别在于前者用逗号分隔数据,而后者用制表符。with open('test.csv') as f: data = f.read().replace(',', '\t')with open('test.tsv','w') as f: f.write(data)""" 用replace方法将,替换成\t 然后在写入文件的时候...原创 2019-08-26 17:53:29 · 5394 阅读 · 1 评论 -
pickle的Python版本问题
在不同Python版本生成的pickle文件不能跨版本直接调用,会报错。python3->python2在Python2中需要用到Python3生成的pickle时,需要在Python3中先将pickle保存为Python2适用版本(好拗口...)然后再在Python2中读取。Python2->python3python3中需要用到Python2生成的pickl...原创 2019-10-10 14:56:14 · 1744 阅读 · 0 评论