Using numpy to write an array to stdout
How about the following code?
>>> a = numpy.array([[2., 0., 0.], [0., 2., 0.], [0., 0., 4.]])>>> numpy.savetxt(sys.stdout, a, fmt='%.4f')1.0000 2.0000 3.00000.0000 2.0000 0.00000.0000 0.0000 4.0000
In Python 3+, use numpy.savetxt(sys.stdout.buffer, ...)
.