Python基础教程,Python入门教程(超详细)

CentOS7下OpenVPN Access Server 2.12.0安装与智能分流配置指南 本文详细介绍了在CentOS7系统上安装OpenVPN Access Server 2.12.0并进行智能分流配置的完整指南。从环境准备、核心安装到智能分流策略的深度配置,提供了经过验证的优化方案和故障排查技巧,帮助用户实现高效的VPN网关部署和流量管理。 阅读详情

Python由荷兰数学和计算机科学研究学会 于1990 年代初设计,作为一门叫做ABC语言的替代品。Python语法和动态类型,以及解释型语言的本质,使它成为多数平台上写脚本和快速开发应用的编程语言。

目录
为什么使用Python
Python应用场合
Hello world
国际化支持
便易用的计算器
字符串,ASCII和UNICODE
使用List
条件和循环语句
如何定义函数
文件I/O
异常处理
类和继承
包机制

为什么使用Python

假设我们有这么一项任务:简单测试局域网中的电脑是否连通.这些电脑的ip范围从192.168.0.101到192.168.0.200.

思路:用shell编程.(Linux通常是bash而Windows是批处理脚本).例如,在Windows上用ping ip 的命令依次测试各个机器并得到控制台输出.由于ping通的时候控制台文本通常是"Reply from … " 而不通的时候文本是"time out … " ,所以,在结果中进行字符串查找,即可知道该机器是否连通.

实现:Java代码如下:

String cmd="cmd.exe ping ";
String ipprefix=“192.168.10.”; int begin=101; int end=200;
Process p=null; for(int i=begin;i<end;i++){
p= Runtime.getRuntime().exec(cmd+i);
String line = null;
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
while((line = reader.readLine()) != null)
{
//Handling line , may logs it. }
reader.close();
p.destroy();
}
这段代码运行得很好,问题是为了运行这段代码,你还需要做一些额外的工作.这些额外的工作包括:

编写一个类文件
编写一个main方法
将之编译成字节代码
由于字节代码不能直接运行,你需要再写个小小的bat或者bash脚本来运行.
当然,用C/C++同样能完成这项工作.但C/C++不是跨平台语言.在这个足够简单的例子中也许看不出C/C++和Java实现的区别,但在一些更为复杂的场景,比如要将连通与否的信息记录到网络数据库.由于Linux和Windows的网络接口实现方式不同,你不得不写两个函数的版本.用Java就没有这样的顾虑.

同样的工作用Python实现如下:

import subprocess
cmd=“cmd.exe” begin=101 end=200 while begin<end:
p=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
p.stdin.write(“ping 192.168.1.”+str(begin)+“\n”)
p.stdin.close()
p.wait()
print “execution result: %s”%p.stdout.read()
对比Java,Python的实现更为简洁,你编写的时间更快.你不需要写main函数,并且这个程序保存之后可以直接运行.另外,和Java一样,Python也是跨平台的.

有经验的C/Java程序员可能会争论说用C/Java写会比Python写得快.这个观点见仁见智.我的想法是当你同时掌握Java和Python之后,你会发现用Python写这类程序的速度会比Java快上许多.例如操作本地文件时你仅需要一行代码而不需要Java的许多流包装类.各种语言有其天然的适合的应用范围.用Python处理一些简短程序类似与操作系统的交互编程工作最省时省力.

Python应用场合

足够简单的任务,例如一些shell编程.如果你喜欢用Python设计大型商业网站或者设计复杂的游戏,悉听尊便.

Hello world

安装完Python之后(我本机的版本是2.5.4),打开IDLE(Python GUI) , 该程序是Python语言解释器,你写的语句能够立即运行.我们写下一句著名的程序语句:

print “Hello,world!”
并按回车.你就能看到这句被K&R引入到程序世界的名言.

在解释器中选择"File"–“New Window” 或快捷键 Ctrl+N , 打开一个新的编辑器.写下如下语句:

print “Hello,world!”
raw_input("Press enter key to close this window! ");
保存为a.py文件.按F5,你就可以看到程序的运行结果了.这是Python的第二种运行方式.

找到你保存的a.py文件,双击.也可以看到程序结果.Python的程序能够直接运行,对比Java,这是一个优势.

国际化支持

我们换一种方式来问候世界.新建一个编辑器并写如下代码:

print “欢迎来到奥运中国!”
raw_input(“Press enter key to close this window!”);
在你保存代码的时候,Python会提示你是否改变文件的字符集,结果如下:

-- coding: cp936 --

print “欢迎来到奥运中国!”
raw_input("Press enter key to close this window! ");
将该字符集改为我们更熟悉的形式:

-- coding: GBK --

print “欢迎来到奥运中国!” # 使用中文的例子
raw_input(“Press enter key to close this window”);
程序一样运行良好.

便易用的计算器
用微软附带的计算器来计数实在太麻烦了.打开Python解释器,直接进行计算:

a=100.0
b=201.1
c=2343
print (a+b+c)/c

字符串,ASCII和UNICODE
可以如下打印出预定义输出格式的字符串:
print “”" Usage: thingy [OPTIONS]
-h Display this usage message
-H hostname Hostname to connect to “”"
字符串是怎么访问的?请看这个例子:

word=“abcdefg” a=word[2]
print "a is: "+a
b=word[1:3]
print "b is: "+b # index 1 and 2 elements of word.
c=word[:2]
print "c is: "+c # index 0 and 1 elements of word.
d=word[0:]
print "d is: "+d # All elements of word.
e=word[:2]+word[2:]
print "e is: "+e # All elements of word.
f=word[-1]
print "f is: "+f # The last elements of word.
g=word[-4:-2]
print "g is: "+g # index 3 and 4 elements of word.
h=word[-2:]
print "h is: "+h # The last two elements.
i=word[:-2]
print "i is: "+i # Everything except the last two characters
l=len(word)
print "Length of word is: "+ str(l)
请注意ASCII和UNICODE字符串的区别:

print “Input your Chinese name:” s=raw_input("Press enter to be continued ");
print "Your name is : " +s;
l=len(s)
print “Length of your Chinese name in asc codes is:”+str(l);
a=unicode(s,“GBK”)
l=len(a)
print “I’m sorry we should use unicode char!Characters number of your Chinese \ name in unicode is:”+str(l);

使用List

类似Java里的List,这是一种方便易用的数据类型:

word=[‘a’,‘b’,‘c’,‘d’,‘e’,‘f’,‘g’]
a=word[2]
print "a is: "+a
b=word[1:3]
print "b is: " print b # index1 and 2 elements of word.
c=word[:2]
print "c is: " print c # index0 and 1 elements of word.
d=word[0:]
print "d is: " print d # All elements of word.
e=word[:2]+word[2:]
print "e is: " print e # All elements of word.
f=word[-1]
print "f is: " print f # The last elements of word.
g=word[-4:-2]
print "g is: " print g # index3 and 4 elements of word.
h=word[-2:]
print "h is: " print h # The last two elements.
i=word[:-2]
print "i is: " print i # Everything except the last two characters
l=len(word)
print "Length of word is: "+ str(l)
print "Adds new element[图片上传中…(image-b4ced-1616074265420-0)] " word.append(‘h’)
print word

条件和循环语句

Multi-way decision

x=int(raw_input(“Please enter an integer:”)) if x<0:
x=0 print"Negative changed to zero" elif x==0:
print “Zero” else:
print “More” # Loops List
a= [‘cat’, ‘window’, ‘defenestrate’] for x ina:
print x, len(x)

如何定义函数

Define and invoke function.

def sum(a,b):
return a+b
func = sum
r = func(5,6)
print r

Defines function with default argument

def add(a,b=2):
return a+b
r=add(1)
print r
r=add(1,5)
print r
并且,介绍一个方便好用的函数:

The range() function

a =range(5,10)
print a
a = range(-2,-7)
print a
a = range(-7,-2)
print a
a = range(-2,-11,-3) # The 3rd parameter stands for step
print a

文件I/O

spath=“D:/download/baa.txt” f=open(spath,“w”) # Opens file for writing.Creates this file doesn’t exist. f.write(“First line 1.\n”)
f.writelines(“First line 2.”)
f.close()
f=open(spath,“r”) # Opens file forreading for line in f:
print line
f.close()

异常处理

s=raw_input(“Input your age:”) if s ==“”:
raise Exception(“Input must no be empty.”) try:
i=int(s)
except ValueError:
print “Could not convert data to an integer.” except:
print"Unknown exception!" else: # It is useful for code that must be executed if the try clause does not raise an exception
print “You are %d” % i," years old" finally: # Clean up action
print “Goodbye!”

类和继承

class Base:
def init(self):
self.data =[]
def add(self, x):
self.data.append(x)
def addtwice(self, x):
self.add(x)
self.add(x)

Child extends Base class Child(Base):

def plus(self,a,b):
    return a+b

oChild =Child()
oChild.add(“str1”)
print oChild.data
print oChild.plus(2,3)

包机制

每一个.py文件称为一个module,module之间可以互相导入.请参看以下例子:

a.py

def add_func(a,b):
return a+b

b.py

from a import add_func # Also can be : import a
print “Import add_func from module a”
print"Result of 1 plus 2 is: " print add_func(1,2) # If using “import a” , then here should be “a.add_func”
module可以定义在包里面.Python定义包的方式稍微有点古怪,假设我们有一个parent文件夹,该文件夹有一个child子文件夹.child中有一个module a.py . 如何让Python知道这个文件层次结构?很简单,每个目录都放一个名为_init_.py 的文件.该文件内容可以为空.这个层次结构如下所示:

parent
–_init.py
–child
– _init.py
–a.py
b.py
那么Python如何找到我们定义的module?在标准包sys中,path属性记录了Python的包路径.你可以将之打印出来:

import sys
print sys.path
通常我们可以将module的包路径放到环境变量PYTHONPATH中,该环境变量会自动添加到sys.path属性.另一种方便的方法是编程中直接指定我们的module路径到sys.path 中:

import sys
sys.path.append(‘D:\download’)
from parent.child.a import add_func
print sys.path
print “Import add_func from module a” print"Result of 1 plus 2 is: " print add_func(1,2)

读者福利:知道你对Python感兴趣,便准备了这套python学习资料

👉[[CSDN大礼包:《python安装包&全套学习资料》免费分享]](安全链接,放心点击)

对于0基础小白入门:

如果你是零基础小白,想快速入门Python是可以考虑的。
一方面是学习时间相对较短,学习内容更全面更集中。
二方面是可以找到适合自己的学习方案

包括:Python激活码+安装包、Python web开发,Python爬虫,Python数据分析,Python自动化测试学习等教程。带你从零基础系统性的学好Python!

零基础Python学习资源介绍

  • ① Python所有方向的学习路线图,清楚各个方向要学什么东西
  • ② 600多节Python课程视频,涵盖必备基础、爬虫和数据分析
  • ③ 100多个Python实战案例,含50个超大型项目详解,学习不再是只会理论
  • ④ 20款主流手游迫解 爬虫手游逆行迫解教程包
  • ⑤ 爬虫与反爬虫攻防教程包,含15个大型网站迫解
  • ⑥ 爬虫APP逆向实战教程包,含45项绝密技术详解
  • ⑦ 超300本Python电子好书,从入门到高阶应有尽有
  • ⑧ 华为出品独家Python漫画教程,手机也能学习
  • ⑨ 历年互联网企业Python面试真题,复习时非常方便

👉Python学习路线汇总👈

Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。(全套教程文末领取哈)
在这里插入图片描述

👉Python必备开发工具👈

img

温馨提示:篇幅有限,已打包文件夹,获取方式在:文末

👉Python学习视频600合集👈

观看零基础学习视频,看视频学习是最快捷也是最有效果的方式,跟着视频中老师的思路,从基础到深入,还是很容易入门的。
在这里插入图片描述

👉实战案例👈

光学理论是没用的,要学会跟着一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。
在这里插入图片描述

👉100道Python练习题👈

检查学习结果。
在这里插入图片描述

👉面试刷题👈

在这里插入图片描述

在这里插入图片描述

👉python副业兼职与全职路线👈

在这里插入图片描述

上述这份完整版的Python全套学习资料已经上传CSDN官方,如果需要可以微信扫描下方CSDN官方认证二维码 即可领取

(入门向)在Ubuntu22.04.3安装Matlab2021b,以及无法安装在当前目录下的解决办法(见最后) 还有这个/usr/local是只读状态,我试过sudo chmod..去改那个文件的读,结果还是安装不了,我不是这个默认路径,因为它文件夹还是只读,于是我在matlab2021b下创了一个bin,并选上。输入完成后,依次按y,因为里面有三个文件,他会让你确定3次密码,直接yyy跳过即可。你可能会遇到装不下的情况,这个软件占30g,可是你分配给虚拟机就剩10g。,于是我去Downloads下建了一个matlab2021b文件夹,果然好使,3).此时,会提示你输入密码,因为这个rar是有密码的, 阅读详情

相关推荐

嵌入式学习之QT学习---14 QT跨平台运行之把QT程序交叉编译到ARM开发板

想要把qt工程放到开发板上运行,就需要用到交叉编译。由于qt是跨平台的,所以只需要换个编译器编译一下就可以。 以“定时器”的例子为例,在移植之前还需要进行一个准备工作,在windows下运行的时候,电脑屏幕很大,但是运行的窗口只有一点点大,开发板也有外接屏幕,如何让运行窗口自动适配开发板的外接屏幕呢?令其占满屏幕显示,而不是一小块。 第一步:需要设置一下,先给ui布局,如果不布局,控件就不会随着屏幕的大小的变化而变化。 第二步:利用代码来获取屏幕的大小,给widget.cpp文件下添加如下代码 #inclu

qq_42822743的博客 5461

【2024】Python入门,详细基础教程,零基础入门,详细图文

Python入门基础介绍

weixin_42399800的博客 17万+

利用Pandas进行高效网络数据获取

本文将重点介绍如何使用Pandas库进行网络爬虫。爬取数据是获取互联网上信息的常见方式之一,而Pandas作为一种强大的数据处理和分析工具,为我们提供了便捷的方法来处理和清洗从网页上获取的数据。文章将从爬取网页数据开始,包括使用Python的Requests库发送HTTP请求获取网页内容,并使用Pandas的功能来解析和提取所需的数据。我们还将讨论如何处理网页中的表格数据、处理和清洗数据、保存数据到文件等常见任务。

ak_bingbing的博客 1441

python入门教程(非常详细),python基础教程 入门教程

用Python写网络爬虫》作者: 【澳】Richard Lawson(理查德 劳森)本书讲解了如何使用Python来编写网络爬虫程序,内容包括网络爬虫简介,从页面中抓取数据的三种方法,提取缓存中的数据,使用多个线程和进程来进行并发抓取,如何抓取动态页面中的内容,与表单进行交互,处理页面中的验证码问题,以及使用Scarpy和Portia来进行数据抓取,并在最后使用本书介绍的数据抓取技术对几个真实的网站进行了抓取,旨在帮助读者活学活用书中介绍的技术。而不同的编程语言,干同一个活,编写的代码量,差距也很大。

神器榜 16万+

硬件即代码:用软件工程思维拆解F450无人机装配的模块化设计哲学

本文探讨了如何用软件工程思维重构DJI-F450无人机的模块化设计,将硬件装配提升为可编程系统。通过硬件抽象层、控制系统分层架构和扩展槽位设计模式,展示了无人机装配的模块化哲学,并结合实际案例说明如何优化性能与安全性。

weixin_29294975的博客 390

新手避坑指南:HT7036计量芯片SPI读取电压的完整流程(从复位到校准)

本文详细介绍了HT7036计量芯片的SPI读取电压完整流程,从硬件准备到校准设置,重点解析了复位引脚处理、SPI通信配置、芯片初始化及数据处理等关键步骤。针对常见问题如晶振焊接、SPI时序错误等提供实用解决方案,帮助开发者高效完成电压测量与校准。

weixin_30070339的博客 336

10年程序员职业生涯感悟—写给正在迷茫的你

希望能带给大家不一样的参考。或者能提前预防,少走弯路!

pythonandaiot的博客 1万+

Aurix TC3xx系列MCU ResourceM模块配置(多核资源分配)

为减轻主核的负载率或者平衡各个核的资源分配,通常需要把一些MCU内部资源分配到从核上,在EB tresos工具中,通过ResourceM模块实现多核资源分配。

m0_38045338的博客 1392

Python入门教程(非常详细)从零基础入门到精通,看完这一篇就够了

本文罗列了了python零基础入门到精通的详细教程,内容均以知识目录的形式展开。

2301_76161259的博客 3万+

9篇3章3节:FAERS数据库公共仪表板搜索功能操作与解析

FAERS(FDA不良事件报告系统)公共仪表板是一个强大的工具,用于查询和分析药物及生物制品的不良事件数据。通过该仪表板,用户可以按药品或不良反应进行搜索,查看报告数量、事件类型及时间分布,从而辅助药物安全性分析和科研研究。本文重点介绍仪表板的搜索功能,包括按产品和按不良反应查询的操作步骤、筛选与多维数据分析方法,以及关键概念的解释,帮助用户科学、理性地使用FAERS数据,提升用药决策的准确性和安全性。

MD Code 1596

基于51单片机的电子记分牌的设计

基于51单片机的电子记分牌的设计 电子记分牌基于51单片机的电子记分牌的设计摘要1 引言2 总体设计方案2.1 设计思路(1)设计要求(2)设计思路(3)设计方案2.3综合设计方框图(1)硬件设计框图(2)软件设计3 设计原理分析3.1 电源、复位、下载电路的设计(见图1、2、3)3.2 时钟电路的设计3.3 矩阵键盘电路的设计3.4 数码管显示电路设计4程序代码 摘要 本设计为电子记分牌设计,是以STC89C52芯片为核心,辅以必要电路设计进行的。用4位LED七段数码管显示比赛两方的分数(每方分数用2位

行走的皮卡丘 2042

Python入门教程(从小白到高级)(新版)

Python从一无所知到精通(新版) 吐槽:Hello,everyone.经历完广东中考折磨的我回来啦!不得不说这届广东考生真的有些困难,先后经历了疫情,然后这次中考又来了一份折磨人的数学试卷(初高中衔接,难度我也觉得有些大)…最后我也不多说了,但愿看到这篇教程的广东初三中考生知道过去的都过去了,不要再这么纠结与郁闷。人生路漫漫,不必因为数学失利而感到绝望,毕竟你难别人也会觉得难,你死了别人也可能跟你一样陪葬。收拾好行装,整理好心态,重新出发,活在当下,为未来努力奋斗才是实在。同时也祝愿广州考生能在七月的中

weixin_47585269的博客 26万+

AutoSAR系列讲解(实践篇)12.1-Diagnostics简介

主要概括性的讲解了诊断协议UDS和AutoSAR的诊断架构

雪云飞星的博客 1万+

电脑入门基础教程_Python入门教程:超详细1小时学会Python

云豆贴心提醒,本文阅读时间9分钟1.Hello world安装完Python之后,打开IDLE(Python GUI) ,该程序是Python语言解释器,你写的语句能够立即运行。我们写下一句著名的程序语句:并按回车,你就能看到这句被K&R引入到程序世界的名言。在解释器中选择"File"--"New Window" 或快捷键 Ctrl+N , 打开一个新的编辑器。写下如下语句:保存为a.py...

weixin_39830688的博客 329

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

python基础教程数据分析_Python入门教程 超详细1小时学会Python

Python入门教程 超详细1小时学会Python本文适合有经验的程序员尽快进入Python世界.特别地,如果你掌握Java和Javascript,不用1小时你就可以用Python快速流畅地写有用的Python程序.为什么使用Python假设我们有这么一项任务:简单测试局域网中的电脑是否连通.这些电脑的ip范围从192.168.0.101到192.168.0.200.思路:用shell编程.(Li...

weixin_30523989的博客 309

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

【Python 基础教程 05】超详细解析Python3注释:全面入门教程,初学者必读,了解Python如何 进行注释

【Python 基础教程 05】超详细解析Python3注释:全面入门教程,初学者必读,了解Python如何 进行注释

探索C++编程的奥秘,分享深入的技术见解和实践,旨在激发读者创造力与解决问题的思维。 870

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【Python 基础教程 运算符06】Python3运算符超详细解析:全面入门教程,初学者必读

【Python 基础教程 06】Python3运算符超详细解析:全面入门教程,初学者必读 超详细解析Python3注释:全面入门教程,初学者必读

探索C++编程的奥秘,分享深入的技术见解和实践,旨在激发读者创造力与解决问题的思维。 619

【Python 基础教程 03 类型转换】从隐式到显式:全面理解Python数据类型转换的超详细初学者入门教程

【Python 基础教程 03】从隐式到显式:全面理解Python数据类型转换的超详细初学者入门教程

探索C++编程的奥秘,分享深入的技术见解和实践,旨在激发读者创造力与解决问题的思维。 3111

python入门教程:超详细1小时学会Python

简介(联系小编 即可自动获取大量python视频教程以及各类PDF!) 1.Hello world 安装完Python之后,打开IDLE(Python GUI) ,该程序是Python语言解释器,你写的语句能够立即运行。 我们写下一句著名的程序语句: 并按回车,你就能看到这句被K&R引入到程序世界的名言。 在解释器中选择"File"–“New Window” 或快捷键 Ctrl+N , 打开一个新的编辑器。 写下如下语句: 保存为a.py文件。 按F5,你就可以看到程序的运行结果了。

zihong523的博客 534

这才是最适合新手的python基础教程,640页超详细

python入门虽然简单,很多新手依然卡在基础安装阶段,大部分教程对一些基础内容都是一带而过,好多新手朋友,对一些基础知识常常一知半解,需要在网上查询很久。扎实的基础知识,对之后的学习、工作都是非常必要的。**这份640页的python基础教程,平常所有的疑难点都可以从中找到答案(比培训机构讲的都详细)。最基础的编程环境搭建就做了84页的详细讲解!其他基础语法、函数、模块和包均一一精细解答。**新手必备!python编程基础(33P)python编程环境搭建(84P)

Python栈 415

python详细教程-Python入门教程:超详细1小时学会Python

1.Hello world安装完Python之后,打开IDLE(Python GUI) ,该程序是Python语言解释器,你写的语句能够立即运行。我们写下一句著名的程序语句:并按回车,你就能看到这句被K&R引入到程序世界的名言。在解释器中选择"File"--"New Window" 或快捷键 Ctrl+N , 打开一个新的编辑器。写下如下语句:保存为a.py...

weixin_37988176的博客 251

Python基础教程,Python入门教程

Python 是一门上手简单、功能强大、通用型的脚本编程语言。Python 类库极其丰富,这使得 Python 几乎无所不能,网站开发、软件开发、大数据分析、网络爬虫、机器学习等都不在话下。 这套 Python 基础教程不是教科书,不会玩弄概念,而是力求口语化、通俗化,让大家尽快入门。 如果小朋友出于兴趣学习本教程,可先引导他阅读教程的前半部分,这是基础;如果你想全面掌握 Python 编程,...

weixin_39655220的博客 1万+

Python基础教程(入门教程),30分钟玩转Python编程!

这是一篇针对初学者的 [Python]基础教程,只要你认真阅读,花费 30 分钟即可快速了解 Python。 这篇 Python 入门教程讲解的知识点包括:Python 编程环境的搭建、Python 基本操作入门、Python 数据类型、Python 语句和函数。 Python环境下载和配置 根据 Windows 版本(64位/32位)从 Python 官网安装下载对应的版本,如图 1 所示。 图 1 下载Python 官方下载网址:[https://www.python.org/] 下载完成后,

MC_XY的博客 1万+

Python爬虫入门教程:从零开始抓取网页数据(超详细版)

嘿!欢迎来到这篇超详细的Python爬虫教程!如果你对爬虫一无所知,别担心!我会用最简单的方式带你从零开始,一步步掌握爬虫的核心技能。

2301_81233957的博客 2830
上一篇: 这15个程序员接单平台,让我每个月收入20K!
下一篇: Python基础知识点(入门基础知识点)
智泊AI官方
博客等级 码龄6年 8639粉丝 2667原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值