From: Sebastian H. <ha...@ms...> - 2003-11-22 00:55:37
|
Hi Alexander, Thanks for your reply and yes, I would be very interested to see more of your "pretty print" code. I am trying to put together all kinds of useful things to make python ( with numarray and scipy) a possible replacement for Matlab... I am not hoping for a similarly big documentation and help system, but just the fact that it's free ( doesn't need to connect to a "license server" every other minute) and that it happily supports single-precision arrays ( not to mention memmap array !) should make it interesting. I know that I probably should use IPython, but I also run python embedded in a wxWindows app and therefore use pyCrust. Thanks again, Sebastian Haase ----- Original Message ----- From: "Alexander Schmolck" <a.s...@gm...> To: "Sebastian Haase" <ha...@ms...> Cc: <num...@li...> Sent: Friday, November 21, 2003 4:37 PM Subject: Re: [Numpy-discussion] Community Poll: numarray default underflow handling == "ignore" ? > "Sebastian Haase" <ha...@ms...> writes: > > > My vote would be '-1' ( if that means "I prefer ignore") > > I'm thinking of an INTERACTIVE platform - and so it would just "look nicer" > > without to many warnings. > > Well, it's only a default so you could always deactivate it (for all > interactive sessions in your PYTHONSTARTUP if you wanted). > > > > > Actually on that note: I read some time ago about pythons default for > > printing floats: > > >>> 0.1 > > 0.10000000000000001 > > >>> print 0.1 > > 0.1 > > >>> repr(0.1) > > '0.10000000000000001' > > >>> str(.1) > > '0.1' > > > > Does anyone here have an update on that ? > > > > > What I am especially interested in is when I have a list of (floating point) > > (x,y) positions and > > then typing in the var-name and getting all these ugly numbers is still very > > frustration for me ;-) > > You can customize python's interactive printing behavior any way you like (in > your PYTHONSTARTUP). Here is an example from my old ~/.pythonrc.py (nowadays I > almost exclusively use ipython). > > import pprint > PRETTY_PRINT=1 > _normal_displayhook = sys.displayhook > def _my_displayhook(object): > if PRETTY_PRINT: > # don't bore us with None > if object is not None: > pprint.pprint(object) > else: > _normal_displayhook(object) > sys.displayhook = _my_displayhook > > You could add something to the above to achieve the floating point (or list) > formating you desire (``if type(object) is float:...). > > Since I am a heavy interactive user and found the default floating formating > of arrays somewhat clumsy for interactive work, I also wrote some more > fanciful formatting code for my Numeric/numarray compatible matrix class that > amongst other things offers a number of formating options, including matlab > style. I found that this made my life much easier. > > Thus: > > >>> a > array([[-9.90000000e+01, -9.72817182e+01, 0.00000000e+00, -7.99144631e+01], > [-4.54018500e+01, 4.84131591e+01, 3.03428793e+02, 9.96633158e+02], > [2.88095799e+03, 8.00308393e+03, 2.19264658e+04, 5.97741417e+04]]) > >>> m = matrix(a) > >>> m > matrix(''' > 1.0E+04 * > > -0.00990 -0.00973 0.00000 -0.00799 > -0.00454 0.00484 0.03034 0.09966 > 0.28810 0.80031 2.19265 5.97741 > ''') > >>> m.show('long') > matrix(''' > 1.0E+04 * > > > Columns 0 through 3 > > -0.009900000000000 -0.009728171817154 0.000000000000000 > -0.004540184996686 0.004841315910258 0.030342879349274 > 0.288095798704173 0.800308392757538 2.192646579480672 > > Columns 3 through 4 > > -0.007991446307681 > 0.099663315842846 > 5.977414171519782 > ''') > >>> m.show('+') > m.show('+') > matrix(''' > -- - > -+++ > ++++ > ''') > > etc. > > Adapting this to e.g. format Numeric arrays similarly via the display hook > shouldn't be too hard, I can provide the code if you're interested. > > > 'as > > > > ------------------------------------------------------- > This SF.net email is sponsored by: SF.net Giveback Program. > Does SourceForge.net help you be more productive? Does it > help you create better code? SHARE THE LOVE, and help us help > YOU! Click Here: http://sourceforge.net/donate/ > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > |