随笔分类 -  python

摘要:import numpy as np q_f = open('weight','rb') weight = np.fromfile(q_f, dtype=np.int16) weight = np.reshape(weight,(512,512)).T weight = weight.flatten 阅读全文
posted @ 2021-07-05 15:18 cydcyd 阅读(697) 评论(0) 推荐(0)
摘要:import argparse def main(): parser = argparse.ArgumentParser(description="Demo of argparse") parser.add_argument('-n', dest='name', default='Li') pars 阅读全文
posted @ 2020-11-20 15:34 cydcyd 阅读(75) 评论(0) 推荐(0)
摘要:正则表达式去除中文字之间的空格,保留英文单词之间的空格,对于英文单词中间夹杂着数字的情况,应该保留空格但没有保留 # -*- coding:utf-8 -*- # import re def _clean_space(text): ​ match_regex = re.compile(u'[\u4e 阅读全文
posted @ 2020-10-29 19:05 cydcyd 阅读(1697) 评论(1) 推荐(1)
摘要:python不同语言的字符串连接成文本 # -*- coding:utf-8 -*- # import sys import unicodedata import six _ALPHANUMERIC_CHAR_SET = set( six.unichr(i) for i in xrange(sys. 阅读全文
posted @ 2020-10-29 11:33 cydcyd 阅读(97) 评论(0) 推荐(0)
摘要:这个方法输出结果是正确的 def is_Chinese(text): zhPattern = re.compile(u'[\u4e00-\u9fa5]+') for ch in text: match = zhPattern.search(ch) if(match): return True ret 阅读全文
posted @ 2020-10-28 11:38 cydcyd 阅读(204) 评论(0) 推荐(0)
摘要:1 str = "Wie geht's dir für" 2 print(str) 3 str2 = str.encode(encoding='UTF-8') 4 print(str2) 5 str3 = str2.decode(encoding='UTF-8') 6 print(str3) 7 8 阅读全文
posted @ 2020-10-28 00:18 cydcyd 阅读(55) 评论(0) 推荐(0)