使用aggregate函数计算平均数

原创
2017/06/27 16:57
阅读数 60
nums = sc.parallelize([1,2,3,4])
seqOp = (lambda x, y: (x[0] + y, x[1] + 1))
combOp = (lambda x, y: (x[0] + y[0], x[1] + y[1]))
sumCount = nums.aggregate((0, 0), seqOp, combOp)
from __future__ import division  ##用于python 2.x中使结果为浮点数
sumCount[0] / sumCount[1]
展开阅读全文
打赏
0
0 收藏
分享
加载中
KYO4321博主
https://www.aliexpress.com/item/50618-8ml-Pure-Colors-UV-Gel-Manicure-Nail-Art-Tips-Polish-Design-DIY-1-PCS/32683741646.html?spm=2114.search0103.3.29.XkmwlC&ws_ab_test=searchweb0_0,searchweb201602_5_10152_10065_10151_10344_10068_10345_10342_10343_10340_10341_10541_10562_10084_10083_10307_5680011_10301_10060_10155_10179_10154_10056_10055_10539_10537_10312_10536_10059_10313_10314_10534_10533_100031_10103_10073_10102_10557_10142_10107,searchweb201603_25,ppcSwitch_5&btsid=21756ff0-da1a-4543-871c-420a02a0c3ae&algo_expid=061cc558-d7f1-4be4-94a2-c2b235b17764-3&algo_pvid=061cc558-d7f1-4be4-94a2-c2b235b17764
2017/11/14 10:38
回复
举报
KYO4321博主
https://jingyan.baidu.com/article/676629978df38a54d41b847e.html
2017/11/13 16:06
回复
举报
KYO4321博主
https://www.kaggle.com/account/verify?id=2908ff27-90ac-4178-8c6f-c3509be791db
2017/10/27 09:46
回复
举报
更多评论
打赏
3 评论
0 收藏
0
分享
返回顶部
顶部