From: Nils W. <nw...@ia...> - 2006-07-10 12:34:11
|
Hi all, how can I increase the number of digits in the output of str(.) ? >>> lam**2 493.48022005446808 >>> str(lam**2) '493.480220054' '493.4802200544680' would be fine. Nils |
From: David D. <dav...@lo...> - 2006-07-10 13:08:17
|
On Mon, Jul 10, 2006 at 02:33:52PM +0200, Nils Wagner wrote: > Hi all, >=20 > how can I increase the number of digits in the output of str(.) ? >=20 > >>> lam**2 > 493.48022005446808 > >>> str(lam**2) > '493.480220054' >=20 > '493.4802200544680' would be fine. Maybe something like=20 >>> '%.13f'%(lam**2) David --=20 David Douard LOGILAB, Paris (France) Formations Python, Zope, Plone, Debian : http://www.logilab.fr/formations D=E9veloppement logiciel sur mesure : http://www.logilab.fr/services Informatique scientifique : http://www.logilab.fr/science |
From: Tim H. <tim...@co...> - 2006-07-10 13:30:35
|
Nils Wagner wrote: > Hi all, > > how can I increase the number of digits in the output of str(.) ? > You can't as far as I know. For floats, you can use "%.nf". For example: "%.13f" % 493.4802200544680 -tim > >>>> lam**2 >>>> > 493.48022005446808 > >>>> str(lam**2) >>>> > '493.480220054' > > '493.4802200544680' would be fine. > > Nils > > > > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > > > |
From: Robert K. <rob...@gm...> - 2006-07-10 13:47:30
|
Tim Hochberg wrote: > Nils Wagner wrote: >> Hi all, >> >> how can I increase the number of digits in the output of str(.) ? >> > You can't as far as I know. For floats, you can use "%.nf". For example: > > "%.13f" % 493.4802200544680 The problem is is that he doesn't have a float. He has one of our float64scalar objects. The str() of a real Python float will give as many digits as are necessary to recreate number and no more (or maybe one or two more). A str() of a float64scalar will round according to some rule that I haven't figured out, yet. It doesn't seem to be configurable with numpy.set_printoptions(). -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco |
From: Robert K. <rob...@gm...> - 2006-07-10 14:09:43
|
Robert Kern wrote: > Tim Hochberg wrote: >> Nils Wagner wrote: >>> Hi all, >>> >>> how can I increase the number of digits in the output of str(.) ? >>> >> You can't as far as I know. For floats, you can use "%.nf". For example: >> >> "%.13f" % 493.4802200544680 > > The problem is is that he doesn't have a float. He has one of our float64scalar > objects. The str() of a real Python float will give as many digits as are > necessary to recreate number and no more (or maybe one or two more). A str() of > a float64scalar will round according to some rule that I haven't figured out, > yet. It doesn't seem to be configurable with numpy.set_printoptions(). No, that's entirely wrong. Please ignore the ravings of a madman. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco |
From: David D. <dav...@lo...> - 2006-07-10 14:07:32
|
On Mon, Jul 10, 2006 at 08:46:33AM -0500, Robert Kern wrote: > Tim Hochberg wrote: > > Nils Wagner wrote: > >> Hi all, > >> > >> how can I increase the number of digits in the output of str(.) ? > >> =20 > > You can't as far as I know. For floats, you can use "%.nf". For example: > >=20 > > "%.13f" % 493.4802200544680 >=20 > The problem is is that he doesn't have a float. He has one of our float64= scalar=20 > objects. The str() of a real Python float will give as many digits as are= =20 > necessary to recreate number and no more (or maybe one or two more). A st= r() of=20 > a float64scalar will round according to some rule that I haven't figured = out,=20 > yet. It doesn't seem to be configurable with numpy.set_printoptions(). This is a different ptoblem from the one exposed by Nils. I mean, tha fact that str() on numpy.float64 objects is somewhat obscure is a problem that should obviously be addressed some day. However, as far as I understand Nils' message, the "%.13f" trick is enough for what he need. But I may be wrong... He just want to "increase the number of digits", not have the "optimal" number of digits (as long as this is meaningfull). But I may have missed something. David --=20 David Douard LOGILAB, Paris (France) Formations Python, Zope, Plone, Debian : http://www.logilab.fr/formations D=E9veloppement logiciel sur mesure : http://www.logilab.fr/services Informatique scientifique : http://www.logilab.fr/science |
From: Robert K. <rob...@gm...> - 2006-07-10 14:16:25
|
David Douard wrote: > On Mon, Jul 10, 2006 at 08:46:33AM -0500, Robert Kern wrote: >> Tim Hochberg wrote: >>> Nils Wagner wrote: >>>> Hi all, >>>> >>>> how can I increase the number of digits in the output of str(.) ? >>>> >>> You can't as far as I know. For floats, you can use "%.nf". For example: >>> >>> "%.13f" % 493.4802200544680 >> The problem is is that he doesn't have a float. He has one of our float64scalar >> objects. The str() of a real Python float will give as many digits as are >> necessary to recreate number and no more (or maybe one or two more). A str() of >> a float64scalar will round according to some rule that I haven't figured out, >> yet. It doesn't seem to be configurable with numpy.set_printoptions(). > > This is a different ptoblem from the one exposed by Nils. I mean, tha > fact that str() on numpy.float64 objects is somewhat obscure is a > problem that should obviously be addressed some day. However, as far as > I understand Nils' message, the "%.13f" trick is enough for what he > need. But I may be wrong... He just want to "increase the number of > digits", not have the "optimal" number of digits (as long as this is > meaningfull). > > But I may have missed something. No, you didn't miss anything. I just haven't gotten enough sleep. I thought that Python floats had a __str__ that computed just as many places as necessary, but it looks like it just rounds at 12 places. This is not an adjustable parameter (barring modifying the C code of the interpreter). I also thought that the float scalars were being printed differently. However, the code for the float64scalar __str__ just gets the double value, creates a Python float object from it, and returns the __str__ result from that object. Everything works as intended. Nothing to see here. Move along. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco |