输出加倍并且无序

rqqzpn5f  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(274)

我用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
dsekswqp

dsekswqp1#

输出按字符串排序,字符串包含方括号。您可以通过如下格式化字符串来解决此问题:

print ', '.join(str(item) for item in numpy.asarray(test[f]))

你可以阅读这个和其他一些问题来了解更多细节。

相关问题