首页 文章 精选 留言 我的

精选列表

搜索[python],共10000篇文章
优秀的个人博客,低调大师

[Spark][Python]PageRank 程序

PageRank 程序: file contents: page1 page3 page2 page1 page4 page1 page3 page1 page4 page2 page3 page4 def computeContribs(neighbors,rank): for neighbor in neighbors: yield( neighbor, rank/len(neighbors) ) links = sc.textFile("tst001.txt").map(lambda line: line.split()).map(lambda pages: (pages[0],pages[1]))\ .distinct().groupByKey().persist() ranks=links.map(lambda (page,neighbors): (page,1.0) ) In [4]: for x in range(1): ...: print "links count:"+links.count() ...: print "ranks count:" ranks.count() In [11]: for x in range(3): ....: contribs=links.join(ranks).flatMap( lambda (page,(neighbors,rank)): computeContribs(neighbors,rank) ) ....: ranks=contribs.reduceByKey(lambda v1,v2: v1+v2).map(lambda (page,contrib): (page,contrib*0.85+0.15)) ....: for rank in ranks.collect(): print rank (u'page2', 0.394375) (u'page3', 1.2619062499999998) (u'page4', 0.8820624999999999) (u'page1', 1.4616562499999997) 本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/p/7614711.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

python异常继承树

BaseException + - - SystemExit + - - KeyboardInterrupt + - - GeneratorExit + - - Exception + - - StopIteration + - - StandardError | + - - BufferError | + - - ArithmeticError | | + - - FloatingPointError | | + - - OverflowError | | + - - ZeroDivisionError | + - - AssertionError | + - - AttributeError | + - - EnvironmentError | | + - - IOError | | + - - OSError | | + - - WindowsError (Windows) | | + - - VMSError (VMS) | + - - EOFError | + - - ImportError | + - - LookupError | | + - - IndexError | | + - - KeyError | + - - MemoryError | + - - NameError | | + - - UnboundLocalError | + - - ReferenceError | + - - RuntimeError | | + - - NotImplementedError | + - - SyntaxError | | + - - IndentationError | | + - - TabError | + - - SystemError | + - - TypeError | + - - ValueError | + - - UnicodeError | + - - UnicodeDecodeError | + - - UnicodeEncodeError | + - - UnicodeTranslateError + - - Warning + - - DeprecationWarning + - - PendingDeprecationWarning + - - RuntimeWarning + - - SyntaxWarning + - - UserWarning + - - FutureWarning + - - ImportWarning + - - UnicodeWarning + - - BytesWarning ============================================================================== 本文转自被遗忘的博客园博客,原文链接:http://www.cnblogs.com/rollenholt/archive/2011/11/25/2263724.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Python-字典遍历

遇到个小问题: 我将十本书的[书名列表]赋值给字典的title键值,将[作者列表]赋值给‘author’键值。现在想一个书名,一个作者的输出。使用嵌套循环遍历一共得到了10*10=100次书名和作者(笑)。 for ti,au in dic[‘title’],dic[‘author’]: 这是我下意识写出的一行代码,然而不能这样遍历。又改成dic[‘title’,’author’]也不可以,有没有会的兄台可以指点我一下。尝试了如下: f.open(‘f:\book.txt’,’a’) for i in f.readlines: #报错,不可遍历 for ti in dic[‘title’]: 看来只能在Excel中输出了。 2018.1.9 更新: 或者直接再将字典单个键的 value 赋值给一个新list,再通过list遍历。 2018.1.15更新: list1 = [ 1, 2, 3] list2 = ['a','b','c',] d = zip(list1,list2) dic1 = dict(d) for i,j in dic1.items(): print (i,j) 结果图: ​

优秀的个人博客,低调大师

[Spark][Python]Wordcount 例子

[training@localhost ~]$ hdfs dfs -cat cats.txt The cat on the mat The aardvark sat on the sofa [training@localhost ~]$ mydata001=sc.textFile('cats.txt') mydata002=mydata001.flatMap(lambda line: line.split(" ")) In [12]: mydata002.take(1) Out[12]: [u'The'] In [13]: mydata002.take(2) Out[13]: [u'The', u'cat'] mydata003=mydata002.map(lambda word : (word,1)) In [10]: mydata003.take(1) Out[10]: [(u'The', 1)] In [11]: mydata003.take(2) Out[11]: [(u'The', 1), (u'cat', 1)] mydata004 = mydata003.reduceByKey(lambda x,y : x+y) In [15]: mydata004.take(1) Out[15]: [(u'on', 2)] In [16]: mydata004.take(2) Out[16]: [(u'on', 2), (u'mat', 1)] In [17]: mydata004.take(3) Out[17]: [(u'on', 2), (u'mat', 1), (u'sofa', 1)] 本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/p/7608625.html,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册