0

0

为什么这个函数的名字是reduce?

php中文网

php中文网

发布时间:2016-06-06 16:23:42

|

2623人浏览过

|

来源于php中文网

原创

我的英语不好,我理解的reduce是减少的意思。但这个函数实现的功能我感觉和减少就没有关系。所以请教该怎样理解reduce?为什么这个函数的名字是reduce?

8023商城系统
8023商城系统

由于8023特殊的数字。所以该项目取名为:8023商城,这个项目是一个简单B2C商城,后台功能不是很完善,许多功能尚未加入,源码仅供参考学习之用,请等待后续版本!项目名称:8023商城 版本号码:1.0页面采用:DIV+TABLE+CSS进行布局。项目结构:B/S结构开发语言:ASP.NET(C#)开发人员:独自开发平台:windows server 2003、windows xp相关软件:Vis

下载

回复内容:

reduce翻译成规约,意思其他答案里面已经讲了。
实际上函数名不应取reduce,应该叫fold,而且要区分foldl和foldr左右两个版本。并行计算里面的那个reduce有个隐含前提,是reduce over monoid,所以结果才与reduce方向无关,可以做有效的并行化。 归约
这是一个函数式编程里面,高阶函数里面很基础的概念。不过我最早听到这个词是在并行计算里面。
函数式编程里面有时也称作 fold ,也就是折叠,这个更好理解吧。详情可参见wikipedia,里面提到了 In functional programming, fold – also known variously as reduce, accumulate, aggregate, compress, or inject
你找一个你觉得好理解的词就OK了。 这就是MapReduce中的reduce,也叫fold。
wikipedia链接:Fold (higher-order function)

SICP中用scheme实现的叫accumulate。
C++中是std::accumulate。

wiki中Folds in various languages部分讲了各种语言中的这个函数的叫法。 reduce在函数式语言里就是要减少的意思,要合并结果,多项变成一项。至于怎么合并,就看reduce的函数是什么。
range得到一个collection(或sequence),里面有多项。reduce函数是add,结果是一项。
当然reduce后也可以还是一个collection,那是因为把collection整体看做一项结果。 别纠结了,这个函数如此难懂,完全不符合python的风格,以致于在python3中被删除了。

题主还是趁早改邪归正,抛弃python2,投入python3的阵营吧! reduce 在这里应该翻译成“归纳”。 verb (used with object), brought, bringing.
1.
to carry, convey, conduct, or cause (someone or something) to comewith, to, or toward the speaker:
Bring the suitcase to my house. He brought his brother to my office.
2.
to cause to come to or toward oneself; attract:
Her scream brought the police. He brought honor to his family by hisheroism.
3.
to cause to occur or exist:
The medication brought instant relief.
4.
to cause to come into a particular position, state, or effect:
to bring the car to a stop.
5.
to cause to appear or occur in the mind; evoke or recall:
The letter brought her memories of youth.
6.
to persuade, convince, compel, or induce:
She couldn't bring herself to sell the painting.
7.
to sell for; fetch:
These lamps will bring a good price.

Verb phrases
9.
bring about, to accomplish; cause:
Land reform brought about a great change in the lives of the commonpeople.
10.
bring around /round,
  1. to convince of a belief or opinion; persuade:
    I think we can bring him around to agreeing with the plan.
  2. to restore to consciousness, as after a faint.
  3. to bring as a visitor:
    They brought around a new employee this morning.
11.
bring down,
  1. to injure, capture, or kill:
    He brought down several ducks on his last hunting trip.
  2. to lessen; reduce:
    I won't buy that lamp unless they bring down the price.
  3. Slang. to cause to be in low spirits; depress:
    The bad news brought him down.
12.
bring forth,
  1. to give birth to; deliver; bear:
    to bring forth a son.
  2. to give rise to; introduce:
    to bring forth a proposal for reducing costs.
13.
bring forward,
  1. to bring to view; show.
  2. to present for consideration; adduce:
    to bring forward an opinion.
14.
bring in,
  1. to yield, as profits or income:
    My part-time job doesn't bring in much, but I enjoy it.
  2. to present officially; submit:
    The jury brought in its verdict.
  3. to cause to operate or yield:
    They brought in a gusher on his property.
  4. to present for consideration, approval, etc.; introduce:
    She brought in six new members last month.
15.
bring off, to accomplish, carry out, or achieve (something):
He brought off his speech with ease.
16.
bring on,
  1. to cause to happen or exist; bring about:
    This incident will surely bring on a crisis.
  2. to introduce; cause to appear:
    Bring on the clowns.
17.
bring out,
  1. to expose; reveal.
  2. to make noticeable or conspicuous in a contrast.
  3. to publish, as a book or play.
  4. to introduce officially into society:
    to bring out a debutante.
18.
bring to,
  1. to bring back to consciousness; revive.
  2. Nautical. to head (a vessel) close to or into the wind so as to halt.
19.
bring up,
  1. to care for during childhood; rear.
  2. to introduce or mention for attention, discussion, action, orconsideration.
  3. to vomit.
  4. to stop or cause to stop quickly:
    to bring up a car at the curb.
  5. Nautical. (of a vessel) to cause to halt, as by lowering an anchor orrunning aground; fetch up.
....
reduce 很多项成一项啊。这个很难理解么?

相关专题

更多
php与html混编教程大全
php与html混编教程大全

本专题整合了php和html混编相关教程,阅读专题下面的文章了解更多详细内容。

6

2026.01.13

PHP 高性能
PHP 高性能

本专题整合了PHP高性能相关教程大全,阅读专题下面的文章了解更多详细内容。

6

2026.01.13

MySQL数据库报错常见问题及解决方法大全
MySQL数据库报错常见问题及解决方法大全

本专题整合了MySQL数据库报错常见问题及解决方法,阅读专题下面的文章了解更多详细内容。

6

2026.01.13

PHP 文件上传
PHP 文件上传

本专题整合了PHP实现文件上传相关教程,阅读专题下面的文章了解更多详细内容。

5

2026.01.13

PHP缓存策略教程大全
PHP缓存策略教程大全

本专题整合了PHP缓存相关教程,阅读专题下面的文章了解更多详细内容。

3

2026.01.13

jQuery 正则表达式相关教程
jQuery 正则表达式相关教程

本专题整合了jQuery正则表达式相关教程大全,阅读专题下面的文章了解更多详细内容。

1

2026.01.13

交互式图表和动态图表教程汇总
交互式图表和动态图表教程汇总

本专题整合了交互式图表和动态图表的相关内容,阅读专题下面的文章了解更多详细内容。

15

2026.01.13

nginx配置文件详细教程
nginx配置文件详细教程

本专题整合了nginx配置文件相关教程详细汇总,阅读专题下面的文章了解更多详细内容。

4

2026.01.13

nginx部署php项目教程汇总
nginx部署php项目教程汇总

本专题整合了nginx部署php项目教程汇总,阅读专题下面的文章了解更多详细内容。

5

2026.01.13

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号