![](https://img-blog.csdnimg.cn/20190927151132530.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
Python
关于Python编程语言的相关的内容
SimonChenHere
PhD Candidate,计算机本,人工智能硕,网络安全博。
展开
-
python跳出两层(多层)循环--使用标志量
break2 = Falsewhile (True): // 省略 while (True): // 省略 if xxx: break2 = True break if (break2): break原创 2021-06-12 09:45:00 · 161 阅读 · 0 评论 -
python 去除读取txt输出时候的换行号
使用splitlines()with open("demo.txt", "r") as f: data = f.read().splitlines() print(data)output[1]: ['35durant', 'teamGSW']详情参考https://www.cnblogs.com/demiao/p/12712509.html原创 2021-06-12 09:43:51 · 555 阅读 · 0 评论 -
argument ‘input‘ (position 1) must be Tensor, not XX
这里:numpy 和 tensor数据相互转换的方法:1.numpy->tensordata = torch.tensor(data)2.tensor->numpy非训练数据(训练结束后的tensor)的转换:data1 = np.array(data1)如果是训练过程中需要转换,则:data_ = data.cpu().data.numpy()https://blog.csdn.net/qq_41368074/article/details/105560274...原创 2020-11-06 19:04:58 · 34719 阅读 · 0 评论 -
Python中__init__和self的意义和作用
由于类可以起到模板的作用,因此,可以在创建实例的时候,把一些我们认为必须绑定的属性强制填写进去。以学生类为例,通过定义一个特殊的__init__方法,在创建实例的时候,就把name,score等属性绑上去:class Student(object): def __init__(self, name, score): self.name = name self.score = score参考blog...转载 2020-10-17 16:06:59 · 467 阅读 · 0 评论 -
Python 中的 if __name__ == ‘__main__‘ 该如何理解
如何简单地理解Python中的if name == ‘main’Python 中的 if name == ‘main’ 该如何理解转载 2020-10-17 15:22:05 · 143 阅读 · 0 评论 -
python:01字串
问题描述 对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能。它们的前几个是:00000 00001000100001100100请按从小到大的顺序输出这32种01串。输入格式 本试题没有输入。 输出格式 输出32行,按从小到大的顺序每行一个长度为5的01串。 样例输出 00000 00001 0001000011 <以下部分省略>#大体上的思想就是i递增,取余数接进空字符串里,然后逆序输出并且空位补上0i=0for i in range(32): .原创 2020-07-03 17:19:36 · 774 阅读 · 0 评论 -
uint和int的区别
int是带符号的,表示范围是:-2147483648到2147483648,即-231到231次方。uint则是不带符号的,表示范围是:2^32即0到4294967295。uint可以使用十进制,二进制,十六进制。和long,ulong,float,double,decimal等预定义可以进行隐式转换。但是需要注意值是否在可转换的范围内,不然会出现异常。...原创 2020-06-11 20:47:10 · 6596 阅读 · 0 评论 -
读取本地fashion_mnist数据集
def load_data(path,files): import gzip import numpy as np paths = [path+ each for each in files ] with gzip.open(paths[0], 'rb') as lbpath: train_labels = np.frombuffer(lbpath.read(), np.uint8, offset=8) with gzip.open(paths[1],原创 2020-06-11 20:28:36 · 1573 阅读 · 1 评论 -
逻辑回归代码实现
#逻辑回归最后要输出一个概率值, import pandas as pd import tensorflow as tf import matplotlib.pyplot as plt data =pd.read_csv(‘dataset/credit-a.csv’,header=None)#这个credit是一个包含个人信用的数据,1代表没有欺诈数据,-1代表有欺诈数据print(data) x = data.iloc[:,:-1] y = data.iloc[:,-1].replace(-1 ,.原创 2020-06-11 20:26:01 · 412 阅读 · 0 评论 -
Tensorflow Data Adapter Error: ValueError: Failed to find data adapter that can handle input
import pandas as pdimport tensorflow as tfimport numpy as npimport matplotlib.pyplot as pltdata = pd.read_csv(‘dataset/Advertising.csv’)#构建散点图,观察tv的广告量和sales的关系,通过散点图的可以明显看出成线性相关plt.scatter(data.TV,data.sales)plt.show()print(data)#x是中间的三列,出去第一列和最.原创 2020-06-10 17:50:37 · 1890 阅读 · 0 评论 -
python matplotlib绘图显示中文
plt.rcParams[‘font.sans-serif’]=[‘SimHei’]plt.rcParams[‘axes.unicode_minus’] = False原创 2020-06-05 17:48:18 · 287 阅读 · 0 评论 -
keras_contrib 安装
安装keras_contribpip install git+https://www.github.com/keras-team/keras-contrib.git原创 2020-05-26 13:17:31 · 706 阅读 · 0 评论 -
Non-ASCII character \xe6 in file
出现这个错误,估计应该使用的是python2.x解决办法1: 在代码页加上这一段话# encoding: utf-8或者:# -*- coding:UTF-8 -*-即可解决此问题。原创 2020-05-23 20:52:40 · 389 阅读 · 0 评论 -
pycharm使用技巧
pycharm快速定位到 变量或者函数或者类的定义 ctrl + 鼠标左键原创 2020-05-22 18:48:12 · 251 阅读 · 0 评论 -
Python文档
https://docs.python.org/zh-cn/3/原创 2020-05-22 18:36:55 · 169 阅读 · 0 评论 -
使用Pycharm将代码同步到GitHub
https://blog.csdn.net/john_bian/article/details/94657057原创 2020-05-15 21:49:00 · 1194 阅读 · 0 评论 -
05NumPy--5.4随机数
原创 2020-05-02 21:30:35 · 148 阅读 · 0 评论 -
05NumPy--5.4矩阵
这里上下两张图的内容好好对比原创 2020-05-02 19:32:40 · 3383 阅读 · 0 评论 -
np.stack() | 数组堆叠
原创 2020-05-02 13:07:23 · 2095 阅读 · 0 评论 -
np.sum() | 不同维度的数组在不同轴方向上相加
https://www.icourse163.org/learn/XUST-1206363802?tid=1206674203#/learn/content?type=detail&id=1213241073&cid=1217985699&replay=true原创 2020-05-02 12:57:14 · 2968 阅读 · 0 评论 -
公式中*和· 号的含义区分(GRU公式)
matrix product是点号*号 等价于 Hadamard*号和 ⊙ 都是表达哈达玛,GRU代码:原创 2020-04-26 00:21:58 · 6849 阅读 · 0 评论 -
05NumPy--5.2创建NumPy数组
#语法:array([列表]/(元祖))import numpy as npa = np.array([1,2,3,3])print(a)print(type(a))创建特殊的数组函数功能描述np.arange()创建数字序列数组np.ones()创建全1数组np.zeros()创建全0数组np.eye()创建单位矩阵np.linspace()创建等差数列np.logsp...原创 2020-05-01 22:37:14 · 4095 阅读 · 0 评论 -
import 导入和from导入的区别
为了避免numpy和Python中同名函数的混淆,第二种from不推荐原创 2020-05-01 22:12:41 · 4296 阅读 · 0 评论 -
05NumPy--5.1多维数组
下一页slide是重点原创 2020-05-01 22:06:58 · 4016 阅读 · 0 评论 -
conda添加清华镜像源在cmd环境下执行下列命令
为conda添加清华镜像源在cmd环境下执行下列命令conda config--add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/freeconda config--add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/maincondaco...原创 2020-05-01 21:56:28 · 2174 阅读 · 1 评论 -
解决Keras 与 Tensorflow 版本之间的兼容性问题,导入keras报错:module 'tensorflow.python.keras.backend' has no attribute
解决Keras 与 Tensorflow 版本之间的兼容性问题https://docs.floydhub.com/guides/environments/原创 2020-04-30 23:34:50 · 8106 阅读 · 0 评论 -
Gensim1.0.0+ 错误'Word2Vec' object has no attribute 'vocab'
原因是Gensim在1.0.0版本之后移动了vocab属性的位置因此在1.0.0之前版本的gensimmodel.vocabgensim 1.0.0+ 中你应该使用model.wv.vocab原创 2020-04-30 23:08:05 · 6527 阅读 · 0 评论 -
python第三方库介绍和安装
Gensim是一款开源的第三方Python工具包,用于从原始的非结构化的文本中,无监督地学习到文本隐层的主题向量表达。它支持包括TF-IDF,LSA,LDA,和word2vec在内的多种主题模型算法,支持流式训练,并提供了诸如相似度计算,信息检索等一些常用任务的API接口https://blog.csdn.net/weixin_42483560/article/details/936565...原创 2020-04-30 22:48:38 · 2489 阅读 · 0 评论 -
python使用turtle库绘制玫瑰花
# RoseDraw.pyimport turtle as t# 定义一个曲线绘制函数def DegreeCurve(n, r, d=1): for i in range(n): t.left(d) t.circle(r, abs(d))# 初始位置设定s = 0.2 # sizet.setup(450*5*s, 750*5*s)t.penco...原创 2020-04-27 19:14:24 · 7050 阅读 · 0 评论 -
Python生成词云
import jiebaimport wordcloudfrom scipy.misc import imread#例子1# txt = open("threekingdoms.txt",encoding='utf-8').read()# w = wordcloud.WordCloud(width=1000, font_path='msyh.ttc', height=700)# w...原创 2020-04-27 19:10:38 · 5910 阅读 · 0 评论 -
sklearn分类_姿态预测问题
#-* coding: utf-8-*-import numpy as npimport pandas as pdfrom sklearn.impute import SimpleImputerfrom sklearn.model_selection import train_test_splitfrom sklearn.metrics import classification_rep...原创 2020-04-27 19:09:41 · 5785 阅读 · 0 评论 -
霍兰德人格分析实例
#HollandRadarDrawimport numpy as npimport matplotlib.pyplot as pltimport matplotlibmatplotlib.rcParams['font.family']='SimHei'radar_labels = np.array(['研究型(I)','艺术型(A)','社会型(S)',\'企业型(E)','常规型(C...原创 2020-04-27 19:07:12 · 5886 阅读 · 0 评论 -
Python输出当前时间
import timeprint(time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime()))原创 2020-04-26 00:19:02 · 6401 阅读 · 0 评论 -
词频统计——三国人物出场次数统计
#三国演义人物的升级版#1.给出排除词库#CalThreeKingdomsV1.py# import jieba# txt = open("threekingdoms.txt", "r", encoding='utf-8').read()# words = jieba.lcut(txt)# counts = {}# for word in words:# if len(w...原创 2020-04-26 00:20:19 · 7122 阅读 · 0 评论 -
BMI指标计算
#CalBMIv1.yheight, weight = eval(input("请输入身高(米)和体重\(公斤)[逗号隔开]:"))bmi = weight / pow(height,2)print("BMI 数值为:{:.2f}".format(bmi))who, nat = "", ""if bmi < 18.5: who, nat = "偏瘦" ,"偏瘦"elif ...原创 2020-04-25 14:40:35 · 6457 阅读 · 0 评论 -
turtle库自动轨迹绘制
#自动轨迹绘制import turtle as tt.title('自动轨迹绘制')t.setup(800,900,0,0)#turtle窗口的位置t.pencolor('red')t.pensize('5')datals = []f = open('data_AutoTraceDraw.txt')for line in f: line = line.replace('\n...原创 2020-04-25 14:39:47 · 7970 阅读 · 0 评论 -
Python基础技术点和常见错误
原创 2020-04-24 23:06:47 · 1217 阅读 · 0 评论 -
python爬虫
待续原创 2020-04-24 15:45:40 · 3107 阅读 · 0 评论