What is an idiomatic way to write a Numpy 2D Array to stdout? e.g. I have an array
a = numpy.array([[2., 0., 0.], [0., 2., 0.], [0., 0., 4.]])
[[ 2. 0. 0.]
[ 0. 2. 0.]
[ 0. 0. 4.]]
That I would like outputted as:
2.0 0.0 0.0
0.0 2.0 0.0
0.0 0.0 4.0
I can do this by converting to a nested list, and then joining the list elements:
print( '\n'.join( [ ' '.join( [ str(e) for e in row ] ) for row in a.tolist() ] ) )
but would like something like:
a.tofile( sys.stdout )
(except this gives a syntax error).