[Numpy-discussion] Printing formatted numerical values

Gerrit Holl gerrit.holl@gmail....
Mon Nov 15 09:12:28 CST 2010

On 15 November 2010 15:32,  <pv+numpy@math.duke.edu> wrote:
> Hi, what is the best way to print (to a file or to stdout) formatted
> numerical values? Analogously to C's printf("%d %g",x,y) etc?

Use the .tofile() method:

numpy.random.random(5).tofile(sys.stdout, ' ', '%s')
0.230466435867 0.609443784908 0.353855676828 0.552641723317 0.186418931597

(works only on "real files", afaik, not on StringIO or similar)


Exploring space at http://gerrit-explores.blogspot.com/
Personal homepage at http://www.topjaklont.org/
Asperger Syndroom: http://www.topjaklont.org/nl/asperger.html

More information about the NumPy-Discussion mailing list