How to print floating point in scientific format?

sdhyok sdhyok at yahoo.com
Mon Aug 11 05:52:29 CEST 2003


Thanks, Alex.

snip

> If you're doing scientific computations in Python and use arrays but
> not Numeric (or its slated-to-be-replacement numarray, of which I
> don't know much yet; or the many things layered atop of and onside
> of Numeric, such as scipy), switch.  You'll be happy you did.
I refer all sequences, but, as you say, particularly numpy arrays.

> I've never heard a scientific programmer complain too badly about
> how Numeric treats arrays, whether they were coming from Fortran
> (the typical case), other higher-level languages, or general purpose
> languages not really suited for scientific computation (such as C).

Right, we can use scientific binary formats, like NetCDF, HDF.
But, we often want to read the data in our naked eyes 
and exchange them with spreadsheet.

> 
> You seem to be focused on readable display of arrays (quite an
> unusual focus for scientific programming).  So, worst case, it's trivial 
> to write a general purpose function that takes an array of ANY size
> and rank and emits it in the way you prefer -- easier than in any
> other language commonly used for scientific programming.
> 
> So, you don't need anything from Python -- just write that blessed
> function and scientifically program to your heart's content.

Trivial to create my own function.
But, surprisingly no common function or command for the work.
Maybe, one solution is

import Numeric as N
N.print(array, format="%.2E")


Daehyok Shin




More information about the Python-list mailing list