Why wont numpy matrix let me print its rows?

Posted by uberjumper on Stack Overflow See other posts from Stack Overflow or by uberjumper
Published on 2010-03-28T05:36:08Z Indexed on 2010/03/28 5:43 UTC
Read the original article Hit count: 291

Filed under:
|

Okay this is probably a really dumb question, however its really starting to hurt. I have a numpy matrix, and basically i print it out row by row. However i want to make each row be formatted and separated properly.

>>> arr = numpy.matrix([[x for x in range(5)] for y in range(5)])
>>> arr
matrix([[0, 1, 2, 3, 4],
        [0, 1, 2, 3, 4],
        [0, 1, 2, 3, 4],
        [0, 1, 2, 3, 4],
        [0, 1, 2, 3, 4]])

Lets say i want to print the first row, and add a '|' between each element:

>>> '|'.join(map(str, arr[0,]))
'[[0 1 2 3 4]]'

Err...

>>> '|'.join(map(lambda x: str(x[0]), arr[0]))
'[[0 1 2 3 4]]'

I am really confused by this behavior why does it do this?

© Stack Overflow or respective owner

Related posts about numpy

Related posts about python