[Numpy-discussion] Casting a float array into a string array

Christopher Barker Chris.Barker at noaa.gov
Fri Oct 5 17:18:40 EDT 2007


Matthieu Brucher wrote:

>                 And if there is a way to add a
>                 formatting option ('1.1f' for instance), it would be
>                 even better.

For full control of the formatting, you can use python's string 
formatting, and a nested list comprehension:

[ ["%.3f"%i for i in r] for r in x]

I don't know how to generalize this to n-d though -- maybe numpy.vectorize?

-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov



More information about the NumPy-Discussion mailing list