我用python编写了一个简单的hadoop程序。
Map器.py:
# !/usr/bin/python
import sys
import numpy
from collections import OrderedDict
for line in sys.stdin:
test = OrderedDict([('1', [11, 5, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]), ('2', [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 3, 4, 0, 0, 0, 0, 1, 0, 0, 0, 29, 28, 18, 12, 11, 11, 10, 9, 9, 9, 8, 8, 8, 6, 6, 6, 5, 5, 4, 4])])
for f in test:
print numpy.asarray(test[f])
减速机.py:
# !/usr/bin/python
import sys
for line in sys.stdin:
print line,
输入文件:
1
2
预期产量:
[11 5 5 5 4 4 4 3 3 3 3 3 3 3 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0]
[ 0 0 0 0 0 0 0 0 1 0 3 4 0 0 0 0 1 0 0 0 29 28 18 12 11 11 10 9 9 9 8 8 8 6 6 6 5 5 4 4]
[11 5 5 5 4 4 4 3 3 3 3 3 3 3 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0]
[0 0 0 0 0 0 0 0 1 0 3 4 0 0 0 0 1 0 0 0 29 28 18 12 11 11 10 9 9 9 8 8 8 6 6 6 5 5 4 4]
实际输出:
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0]
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0]
11 10 9 9 9 8 8 8 6 6 6 5 5 4 4]
11 10 9 9 9 8 8 8 6 6 6 5 5 4 4]
[ 0 0 0 0 0 0 0 0 1 0 3 4 0 0 0 0 1 0 0 0 29 28 18 12 11
[ 0 0 0 0 0 0 0 0 1 0 3 4 0 0 0 0 1 0 0 0 29 28 18 12 11
[11 5 5 5 4 4 4 3 3 3 3 3 3 3 2 2 2 2 2 2 0 0 0 0 0
[11 5 5 5 4 4 4 3 3 3 3 3 3 3 2 2 2 2 2 2 0 0 0 0 0
1条答案
按热度按时间dsekswqp1#
输出按字符串排序,字符串包含方括号。您可以通过如下格式化字符串来解决此问题:
你可以阅读这个和其他一些问题来了解更多细节。