MapReduce Streaming Python AWS 30分钟 (5)matrix multiplication
来源:互联网 发布:手机淘宝1元抢购在哪 编辑:程序博客网 时间:2024/06/06 09:18
mapper.py
#!/usr/bin/env python
import sys
def convert_line_to_iter(file_in):
for line in file_in:
yield line.strip().split(' ')
def emit_key_value():
for k, m, n, v in convert_line_to_iter(sys.stdin):
for i in range(5):
if k == 'a':
print '%s,%s %s,%s,%s' % (m,i,k,n,v)
else:
print '%s,%s %s,%s,%s' % (i,n,k,m,v)
emit_key_value()
reducer.py
#!/usr/bin/env python
import sys
from itertools import groupby
from operator import itemgetter
def convert_mapper_o_to_iter(file_in):
for line in file_in:
yield line.strip().split(' ')
def emit_final_key_value():
for key, el in groupby(convert_mapper_o_to_iter(sys.stdin), itemgetter(0)):
A = {}
B = {}
for item in list(el):
con = item[1].split(',')
if con[0] == 'a':
A[int(con[1])] = int(con[2])
else:
B[int(con[1])] = int(con[2])
ans = 0
for i in range(5):
if i in A and i in B:
ans += A[i]*B[i]
print key, ans
emit_final_key_value()
- MapReduce Streaming Python AWS 30分钟 (5)matrix multiplication
- MapReduce Streaming Python AWS 30分钟 (3)
- MapR M3 MapReduce Streaming Python AWS 30分钟 (1)
- MapR M3 MapReduce Streaming Python AWS 30分钟 (2)
- MapReduce Streaming Python AWS 30分钟 (4) Word Count & Inverted Index
- MapReduce: program of Matrix Multiplication
- Matrix Multiplication
- Matrix Multiplication
- Matrix Multiplication
- Matrix Multiplication
- Matrix multiplication
- Matrix multiplication
- Python+Hadoop Streaming实现MapReduce任务
- Mapreduce streaming
- Matrix Chain Multiplication
- zoj1094 Matrix Chain Multiplication
- Matrix chain multiplication problem
- POJ 3318 Matrix Multiplication
- 15 Step To Hacking Windows Using Social Engineering Toolkit And Backtrack 5
- 修练8年C++面向对象程序设计之体会
- iOS上的设计辅助工具——Skala View
- iOS中的Delegate实现页面间的传值
- Java-性能优化-工具篇-jvisualvm
- MapReduce Streaming Python AWS 30分钟 (5)matrix multiplication
- 做好10种站外推广让你快速获得免费资源
- Android学习日
- ZOJ 3687 The Review Plan I 容斥原理/禁位排列
- Ruby方法
- 1.最简单的操作系统(linux版)(一)运行效果
- hdu 3633
- require 和 load
- JSON是什么,JSON怎么用