How to print floating point in scientific format?

sdhyok sdhyok at yahoo.com
Mon Aug 11 05:41:35 CEST 2003


Writing my own function is definitely one choice.
But, my point is that if some of us are really serious
about scientific/engineering programming,
we must have a common function or command
to print out whole array elements easily with any format we want.

It can be in Numeric (or numarray) package like,

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


Daehyok Shin

bokr at oz.net (Bengt Richter) wrote in message news:<bh6bq6$p1u$0 at 216.39.172.122>...
> On 8 Aug 2003 12:15:53 -0700, sdhyok at yahoo.com (sdhyok) wrote:
> 
> >I want to change the DEFAULT behavior of python
> >to print out all floating points in scientific format?
> >For instance,
> >
> >>x=0.01
> >>print x
> >1.000000E-2 #Like print "%E"%x
> >
> >How can I do it?
> >
> Do you have to use the print statement per se for output?
> I.e., why couldn't you write
> 
>     sciPrint( x, whatever, etc )
> 
> instead of
> 
>     print x, whatever, etc
> 
> Then you could customize sciPrint as you please.
> Or do you have to change the behaviour of existing modules without
> changing their source?
> 
> Regards,
> Bengt Richter




More information about the Python-list mailing list