This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
用函数和yield语句产生生成器,当一个函数内部有yeild语句时,函数不再是函数而是生成器,return的返回值作为迭代完之后的异常抛出。 | |
generator的send方法,把外部的值传给yield | |
迭代器: | |
可直接作用于for循环的对象称之为iterable,可迭代对象,一类是集合数据类型,如list,tuple,dict,set,str等,一类是generator包括生成器和带yield的generator function. 可以使用isinstance()判断一个对象是否是iterable. | |
可以被next()函数调用并不断返回下一个值的对象称之为迭代器:iterator | |
生成器都是iterator对象,但是list,dict,str虽然是iterable,却不是iterator,把list,dict,str等变成iterator可以使用iter()函数。 | |
eval函数:把字符串当成有效的表达式来求值并返回计算结果,可以把list,tuple,dict和string相互转化。 | |
模块的定义、导入: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
匿名函数的标准格式是: | |
handle=@(arglist)express | |
(1)express是一个matlab变量表达式,比如:x+x.^2,sin(x)等 | |
(2)argilst是参数列表; | |
(3)符号@是matlab创建函数句柄的操作符,表示创建有输入参数列表arglist和表达式express确定的函数句柄,并把这个函数句柄返回给变量fhandle,这样,以后就可以通过fhandle来调用定义好的函数了。 | |
如: | |
myfun=@(x)(x+x.^2) | |
1,匿名函数的基本用法。 | |
handle = @(arglist)anonymous_function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
函数的驻点:函数一阶导数为0的点称为函数的驻点 | |
函数的极值点:是在这点附近这一点所对应的函数值最大或最小。 | |
极值点不一定是驻点(极值点处导数可能不存在),驻点不一定是极值点 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sigmoid函数 | |
S(x)=1/(1+e^(-x)) | |
常被用作神经网络阈值函数,将变量映射到0,1之间 | |
loss function: | |
L(yhat,y)=-(ylogyhat+(1-y)log(1-yhat)) | |
y一般是sigmoid函数,在0到1 之间 |