tag 标签: reduce经管大学堂:名校名师名课

相关帖子

版块 作者 回复/查看 最后发表
因子分析与其他分析的概念与区别 计量经济学与统计软件 胖胖小龟宝 2014-2-22 8 20065 grpzxg 2023-5-9 16:08:40
【华尔街系列】Bubbles, Booms, and Busts 第二版 attach_img 金融学(理论版) wwqqer 2015-2-18 33 7995 浑噩没晕 2022-10-29 10:43:10
基于线性预测的欠完全盲子空间反卷积 外文文献专区 能者818 2022-3-30 0 220 能者818 2022-3-30 09:50:00
基于Malliavin演算和非参数方差的美式期权 还原方法 外文文献专区 何人来此 2022-3-8 0 143 何人来此 2022-3-8 12:06:00
请教pruning 算法下的IRF和求解原理 attach_img 宏观经济学 きずな 2014-5-31 2 3115 kkkrain 2017-10-5 19:30:54
Functional Inefficiency The Unexpected Benefits of Wasting Time and Money attach_img 宏观经济学 大家开心 2015-7-13 7 1319 zyh860711 2015-8-6 01:30:54
Improve cash flow and reduce losses from bad debts 文献求助专区 bluelcx 2015-5-10 0 799 bluelcx 2015-5-10 10:34:28
悬赏 Managing urban growth to reduce motorised travel in Beijing: one method of creat - [!reward_solved!] attachment 求助成功区 Tonyhk 2015-3-26 1 569 hello_xn 2015-3-26 15:28:41
悬赏 求文献“When do financial incentives reduce intrinsic motivation? - [!reward_solved!] attachment 爱问频道 猎户星云 2015-3-16 2 845 猎户星云 2015-3-16 15:21:16
给各位兄弟姐妹拜年了。小弟刚接触R一个月,关于R的速度和空间的愚见,请指教。 R语言论坛 yukuang 2015-2-2 4 1690 whlgh 2015-2-3 17:14:46
Asset Rotation: The Demise of Modern Portfolio Theory and the Birth of an Invest attach_img 金融学(理论版) 大家开心 2015-1-22 28 3350 jpang 2015-1-30 15:06:19
An improved demand forecasting method to reduce bullwhip effect in supply chains attachment 运营管理(物流与供应链管理) xiaofei1989 2014-2-17 0 1015 xiaofei1989 2014-2-17 16:21:41
悬赏 Managing stress – Practicing the Taoism principles to reduce stress - [!reward_solved!] attachment 求助成功区 bobthree 2013-12-19 2 682 bobthree 2013-12-21 23:33:11
悬赏 Product attribute bullwhip in the technology planning process - [!reward_solved!] attachment 求助成功区 茵陈 2013-9-17 4 750 zdk_first 2013-9-18 09:59:03
悬赏 Can union support reduce the negative effects of job insecurity on well-being? - [!reward_solved!] attachment 求助成功区 xxrongxr 2013-6-21 3 924 xxrongxr 2013-6-22 09:45:23
Cesarean section to reduce perinatal transmission of human immunodeficiency viru 文献求助专区 ihc7788c 2013-5-6 0 852 ihc7788c 2013-5-6 21:18:24
悬赏 求助Diets containing pistachios reduce systolic blood pressure - [!reward_solved!] attachment 求助成功区 刀剑林 2013-4-1 1 775 Toyotomi 2013-4-1 22:05:40
悬赏 Thinking too much: introspection can reduce the quality - [!reward_solved!] attachment 求助成功区 Aviva 2012-10-29 1 833 liuningzheng 2012-10-29 11:47:16
Does Redistribution Reduce Inequality attachment 劳动经济学 vanhongbin 2010-4-1 0 1271 vanhongbin 2010-4-1 09:31:45

相关日志

分享 python 特殊语法:filter、map 、reduce、lambda
xulimei1986 2015-6-25 17:38
Python特殊语法:filter、map、reduce、lambda Python内置了一些非常有趣但非常有用的函数,充分体现了Python的语言魅力! filter(function, sequence) :对sequence中的item依次执行function(item),将执行结果为True的item组成一个List/String/Tuple(取决于sequence的类型)返回: def f(x): return x % 2 != 0 and x % 3 != 0 filter(f, range(2, 25)) def f(x): return x != 'a' filter(f, "abcdef") 'bcdef' map(function, sequence) :对sequence中的item依次执行function(item),见执行结果组成一个List返回: def cube(x): return x*x*x map(cube, range(1, 11)) def cube(x) : return x + x ... map(cube , "abcde") 另外map也支持多个sequence,这就要求function也支持相应数量的参数输入: def add(x, y): return x+y map(add, range(8), range(8)) reduce(function, sequence, starting_value) :对sequence中的item顺序迭代调用function,如果有starting_value,还可以作为初始值调用,例如可以用来对List求和: def add(x,y): return x + y reduce(add, range(1, 11)) 55 (注:1+2+3+4+5+6+7+8+9+10) reduce(add, range(1, 11), 20) 75 (注:1+2+3+4+5+6+7+8+9+10+20) lambda :这是Python支持一种有趣的语法,它允许你快速定义单行的最小函数,类似与C语言中的宏,这些叫做lambda的函数,是从LISP借用来的,可以用在任何需要函数的地方: g = lambda x: x * 2 g(3) 6 (lambda x: x * 2)(3) 6 我们也可以 把filter map reduce 和lambda结合起来 用,函数就可以简单的写成一行。 例如 kmpathes = filter(lambda kmpath: kmpath, map(lambda kmpath: string.strip(kmpath), string.split(l, ':'))) 看起来麻烦,其实就像用语言来描述问题一样,非常优雅。 对 l 中的所有元素以':'做分割,得出一个列表。对这个列表的每一个元素做字符串strip,形成一个列表。对这个列表的每一个元素做直接返回操作(这个地方可以加上过滤条件限制),最终获得一个字符串被':'分割的列表,列表中的每一个字符串都做了strip,并可以对特殊字符串过滤。 http://hi.baidu.com/black/item/307001d18715fc322a35c747 --------------------------------------------------------------- lambda表达式 返回一个函数对象 例子: func = lambda x,y:x+y func相当于下面这个函数 def func(x,y): return x+y 注意def是语句而lambda是表达式 下面这种情况下就只能用lambda而不能用def map,reduce,filter中的function都可以用lambda表达式来生成! map(function,sequence) 把sequence中的值当参数逐个传给function,返回一个包含函数执行结果的list。 如果function有两个参数,即map(function,sequence1,sequence2)。 例子: 求1*1,2*2,3*3,4*4 map(lambda x:x*x,range(1,5)) 返回值是 reduce(function,sequence) function接收的参数个数只能为2 先把sequence中第一个值和第二个值当参数传给function,再把function的返回值和第三个值当参数传给 function,然后只返回一个结果。 例子: 求1到10的累加 reduce(lambda x,y:x+y,range(1,11)) 返回值是55。 filter(function,sequence) function的返回值只能是True或False 把sequence中的值逐个当参数传给function,如果function(x)的返回值是True,就把x加到filter的返回值里面。一般来说filter的返回值是list,特殊情况如sequence是string或tuple,则返回值按照sequence的类型。 例子: 找出1到10之间的奇数 filter(lambda x:x%2!=0,range(1,11)) 返回值 如果sequence是一个string filter(lambda x:len(x)!=0,'hello')返回'hello' filter(lambda x:len(x)==0,'hello')返回''
0 个评论

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-27 17:41