0

I'm using Python to write a simple Hadoop program.

mapper.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])

reducer.py:

#!/usr/bin/python
import sys
for line in sys.stdin:
    print line,

Input file:

1
2

Expected Output:

[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]

Actual Output:

  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
Objc55
  • 156
  • 1
  • 5
  • 18

1 Answers1

0

The output is sorted as a string, and your string contains brackets. You can solve this by formatting your string as follows:

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

You can read this and this other SO questions for more details.

Community
  • 1
  • 1
cabad
  • 4,555
  • 1
  • 20
  • 33
  • Thank you for the reply. I tried that and it says `error: expected string, numpy.ndarray found` – Objc55 Oct 02 '13 at 21:54
  • The items being joined need to be a string. I edited my answer. – cabad Oct 02 '13 at 21:58
  • Unfortunately it's still out of order, and now begins like this: `, , , , , , , , , 0, ,, , , 0, ,, , , 0, ,, , , 0, ,, , , 1, ,, , , 0, ], )` – Objc55 Oct 04 '13 at 16:44