- 博客(38)
- 收藏
- 关注
原创 Python3 中文乱码 UnicodeEncodeError: ‘latin-1‘ codec can‘t encode characters
Python3 中文乱码 UnicodeEncodeError: ‘latin-1‘ codec can‘t encode characters
2022-08-11 19:37:31
1134
原创 c#创建文件续写文件
readme = "readme.txt"; string txtpath = "D://写文件//" + readme;//文件存放路径 DirectoryInfo directoryInfo = new DirectoryInfo("D://写文件"); if (!directoryInfo.Exists) //判断 文件夹是否存在 { directoryInfo.Create(); }
2022-06-12 22:10:58
974
原创 无法调用自己电脑的gpu,即torch.cuda.is_available()返回false
pythonimport torchprint(torch.__version__)居然是+cpu,明明自己下载的是gpu版本1.9.1+cpu搜寻了一圈从该博主下找到了答案如图:(23条消息) torch.cuda.is_available()返回false——解决办法_Nefu_lyh的博客-优快云博客_torch.cuda.is_available那么接下来按博主的方法卸载torch:因为我是在虚拟环
2022-03-22 11:20:17
8204
3
原创 matplotlib.pyplot中add_subplot
ax = fig.add_subplot(349)参数349的意思是:将画布分割成3行4列,图像画在从左到右从上到下的第9块那第十块怎么办,3410是不行的,可以用另一种方式(3,4,10)。fig = plt.figure()ax = fig.add_subplot(2,1,1)ax.plot(x,y)ax = fig.add_subplot(2,2,3)#重新开始分区,并非从上一处开始ax.plot(x,y)plt.show()...
2021-09-08 16:56:07
306
原创 ValueError: check_hostname requires server_hostname的解决方案
安装sklearn时pip install sklearn报错ValueError: check_hostname requires server_hostname直接关掉vpn即可
2021-08-24 14:43:07
246
原创 python的assert语句
如果assert后面的语句是False,就会有一个AssertionError异常被抛出。报错的语句是assert逗号符号后面的内容assert 1==2,"报错的显示语句."
2021-08-18 18:01:16
151
原创 __getitem__ (self,其他参数)
凡是在类中定义了这个__getitem__ 方法,那么它的实例对象(假定为p),可以像这样p[key] 取值,当实例对象做p[key] 运算时,会调用类中的方法__getitem__。
2021-07-05 19:55:38
439
原创 模型参数变量配置
parser = argparse.ArgumentParser(description='Chinese Text Classification')parser.add_argument('--model', type=str, required=True, help='choose a model: TextCNN, TextRNN, FastText, TextRCNN, TextRNN_Att, DPCNN, Transformer')parser.add_argument('--embedd.
2021-07-01 20:40:51
396
原创 conda安装pytorch
1、新建虚拟环境conda create -n 环境名 python=3.72.进入到虚拟环境中conda activate 环境名3.自己在下载时需要查找自己电脑的cuda版本(在cmd命令窗口输入nvcc –version进行查询),注意千万不要在nvdia面板查询,那个是支持的最高版本,并不是电脑的安装版本4..根据cuda版本选择需要下载的cudnn版本进行下载(对应版本查找及下载地址cuDNN Archive | NVIDIA Developer)5.查找对应的py..
2021-06-29 11:36:00
908
原创 CancelledError: [_Derived_]RecvAsync is cancelled.
CancelledError: [_Derived_]RecvAsync is cancelled.[[{{node Nadam/Nadam/update/ReadVariableOp_4/_187}}]][[gradient_tape/sequential/embedding/embedding_lookup/Reshape/_176]] [Op:__inference_train_function_19125]Function call stack:train_function处..
2021-06-21 19:53:08
359
原创 python Counter()
返回类型是字典类型,用来统计元素的出现个数,计数s2=["你好","是吗","the","111","111","the","the"]c=Counter(s2)print(c)
2021-06-17 11:04:57
132
原创 python的extend()
数组或列表使用extend(),会将括号内参数的s=[]s2=[["你好","是吗","the"],["11","11","112"]]for u in s2: s.extend(u)print(s)
2021-06-17 10:54:32
542
原创 正则表达式的split()方法
re.split(pattern,string,maxsplit=0,flags=0)用pattern分开string。 如果在pattern中捕获到括号,那么所有的组里的文字也会包含在列表里。如果maxsplit非零, 最多进行maxsplit次分隔, 剩下的字符全部返回到列表的最后一个元素。>>>>>> re.split(r'\W+', 'Words, words, words.')['Words', 'words', 'wo...
2021-06-16 21:37:09
2820
原创 python画柱状图
import numpy as npfrom matplotlib import pyplot as pltplt.figure(figsize=(9, 6))n = 5X = ['[2]','[2,3]','[2,3,4]']# X是1,2,3,4,5,6,7,8,柱的个数# numpy.random.uniform(low=0.0, high=1.0, size=None), normal# uniform均匀分布的随机数,normal是正态分布的随机数,0.5-1均匀分布的数,一共有.
2021-05-29 16:01:10
229
原创 python的yield
(8条消息) python中yield的用法详解——最简单,最清晰的解释_mieleizhi0522的博客-优快云博客_yield
2021-05-18 15:21:20
106
原创 summary
tf.summary.scalar("loss", model.loss)tf.summary.scalar("accuracy", model.acc) #生成损失函数和精确度的图tf.summary.merge_all() #将所有的summary保存到磁盘,以便tensorboard显示
2021-05-17 17:55:19
89
原创 No graph definition files were found.
tensorboard使用出现问题,而且使用完整路径,仍然不现实,是因为路径中有中文,修改成英文字符即可
2021-05-17 16:07:41
177
原创 ModuleNotFoundError: No module named ‘tensorflow.tensorboard‘
使用tensorboard可视化时出现报错ModuleNotFoundError: No module named 'tensorflow.tensorboard'由于没有tensorflow中没有tensorboard.py文件,直接在终端执行命令pip install tensorflow.tensorboard即可解决
2021-05-17 14:41:38
802
原创 tf.expand_dims
加一个维度,ne_img = tf.expand_dims(one_img, -1) #-1表示最后一维官方的例子和说明# 't' is a tensor of shape [2]shape(expand_dims(t, 0)) ==> [1, 2]shape(expand_dims(t, 1)) ==> [2, 1]shape(expand_dims(t, -1)) ==> [2, 1]# 't2' is a tensor of shape [2, 3, 5]
2021-05-14 16:24:19
143
原创 tf.nn.embedding_lookup()
tf.nn.embedding_lookup()的用途主要是选取一个张量里面索引对应的元素tf.nn.embedding_lookup( params, ids, partition_strategy='mod', name=None, validate_indices=True, max_norm=None)params:由一个tensor或者多个tensor组成的列表(多个tensor组成时,每个tensor除了第一个维度其他维度.
2021-05-14 16:12:44
119
原创 tf.get_variable()函数
def get_variable(name, shape=None, dtype=None, initializer=None, regularizer=None, trainable=True, collections=None, caching_devic...
2021-05-14 15:34:35
289
原创 tf.Variable()函数tensorflow
tf.Variable.init(初始值, trainable=True, collections=None, validate_shape=True, name=None)trainable属性控制这个变量是否可以被优化器更新,若设置为false就为常量不会被优化器更新
2021-05-14 15:19:35
170
原创 rectified linear unit修正线性单元Relu
Relu = rectified linear unit修正指的是,取值大于0使用Relu函数而不是Sigmoid函数的原因是:在x较大时,Sigmoid函数值接近于1,导数接近0,梯度下降特别慢。而Relu函数的梯度在X>0时一直为1,梯度下降快...
2021-05-13 20:03:12
469
原创 python从第n行开始读取文件
lines = []with codecs.open("./luanxu.txt", 'r', 'gb18030') as infile: for i in infile.readlines()[25701:30519]: lines.append(i)#将读取数据保存新文件中with codecs.open("./cnews.test.txt", 'w','gb18030') as f: for line in lines: f.write(line.
2021-05-12 17:24:37
8006
2
原创 python读取文件前n行
lines = []with codecs.open("./luanxu.txt", 'r', 'gb18030') as infile: for i in range(25700): lines.append(infile.readline())with codecs.open("./cnews.train.txt", 'w','gb18030') as f: for line in lines: f.write(line)读取文件的前25700行.
2021-05-12 17:22:02
2575
原创 python将txt文件的行乱序后,另存新文件
import codecs,randomlines = []#防止乱码,用codecs模块打开中文文件with codecs.open("./huihua.txt", 'r','gb18030') as infile:#将每行数据依次加入数组 for line in infile: lines.append(line)#数组乱序random.shuffle(lines)#乱序后文件写入新文件with codecs.open("./luanxu.txt", 'w'.
2021-05-12 17:18:29
410
原创 python将csv格式文件转存为txt文件
data = pd.read_csv('huihua2222.csv') with open('news_data.txt', 'a+') as f: for line in data.values: f.write((str(line[0]) + '\t' + str(line[1]))) f.write("\\n")
2021-05-12 17:12:51
2204
1
原创 按列索引值删除csv的列数据
import pandas as pddef DeleteColunmn(): # 用panda模块读取文件数据 data = pd.read_csv("huihua2222.csv",encoding="gb18030") # 删除第0列,第3列和第4列数据 data_new=data.drop(data.columns[[0,3,4]],axis=1) #将源文件清空,重新写入删除某几列后的数据 data_new.to_csv("huihua2222.
2021-05-12 17:07:28
477
原创 python读写数据中文乱码问题
import codecswith codecs.open('huihua.txt', 'a',encoding='gb18030') as f:导入上述模块后,只需将encodeing改成gb18030,其范围更广
2021-05-12 17:00:40
294
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人