View this page "suppress scientific notation in matrix"

27 views
Skip to first unread message

archeryguru2000

unread,
Aug 18, 2009, 10:36:21 AM8/18/09
to mpmath


Click on http://groups.google.com/group/mpmath/web/suppress-scientific-notation-in-matrix
- or copy & paste it into your browser's address bar if that doesn't
work.

Fredrik Johansson

unread,
Aug 18, 2009, 2:37:55 PM8/18/09
to mpmath
Such a formatting option is lacking at the moment. A simple way to do
it, given that you don't need high precision, is to use the standard
float formatting mechanism:

>>> a = randmatrix(3,3)/10
>>> for x in a: print "%0.4f" % x
...
0.0069
0.0423
0.0615
0.0302
0.0290
0.0041
0.0934
0.0538
0.0654

You'll need to adapt this code to print the matrix elements line by
line and aligned, but this shouldn't be hard. Let me know if you need
further help.

archeryguru2000

unread,
Aug 18, 2009, 2:55:43 PM8/18/09
to mpmath
Oh no! Don't say that! You've made me cry. :( I should probably
mention that my matrix is a minimum of 12x12. And more generally this
12x12 would only be one-fourth (a quadrant) of the entire solution.
This would yield 144 elements to cycle through, potentially 576
elements... minimum! I'm assuming this could be some serious
computing time? However, this is still better than nothing.

I'm thinking I will try to write a script to actually set the
precision/accuracy within a matrix. I'll do some debugging, and see
what I can come up with. I may have to find a way to 'fix' this size
of the the numbers before they enter the matrix. Any suggestions?

And thank you VERY much for your reply. An unwanted answer is much
better than no answer. ;-)

~~archery~~
Message has been deleted

Fredrik Johansson

unread,
Aug 18, 2009, 3:02:52 PM8/18/09
to mpmath
Hmm, looks like Google Groups ate my code. It should be 'for x in a:
print "%0.4f" % x'.

It will take no time at all to cycle through even several thousand
elements with this :-) E.g. a 24x24 matrix takes 0.004 seconds on my
computer.

archeryguru2000

unread,
Aug 18, 2009, 3:17:39 PM8/18/09
to mpmath
Uh oh! I've made a boo-boo

for L in Loo:
print '%.4f' % L

[code]
Traceback (most recent call last):
File "./L-matrix", line 113, in <module>
print '%.4f' % L
TypeError: float argument required, not numpy.ndarray
[/code]

So I tried to force a float with

for L in Loo:
print '%.4f' % float(L)

But then received this error
[code]
TypeError: only length-1 arrays can be converted to Python scalars
[/code]

Any suggestions?

~~archery~~

Fredrik Johansson

unread,
Aug 18, 2009, 3:23:41 PM8/18/09
to mpmath
If A is a numpy matrix then the easiest way to iterate over it may be
something like:

for row in range(3):
... for col in range(3):
... print '%.4f' % A[row,col]

Vinzent Steinberg

unread,
Aug 19, 2009, 10:47:32 AM8/19/09
to mpmath
This is trivial to fix, see my patch [1], however there is a problem,
so I could not yet commit it.

Vinzent

[1] http://code.google.com/p/mpmath/issues/detail?id=158

archeryguru2000

unread,
Aug 19, 2009, 1:23:28 PM8/19/09
to mpmath
Thank you very much Vinzent. Now for the easy question... how do I
add this patch? For other patches (that were contained in a file) I
would run something like:
$: patch --backup-if-mismatch </name/of/folder/containing-patch-
files>
I'm assuming it should be something similar, say:
$ patch --backup-if-mismatch /path/to/nstr-pass-args.patch

Or am I totally wrong on this? Thanks again for your assistance.
~~archery~~

Vinzent Steinberg

unread,
Aug 20, 2009, 8:08:13 AM8/20/09
to mpmath
For me

$ patch -p0 < nstr-pass-args.patch

works. (I'm also not familiar with this tool :).

Vinzent

archeryguru2000

unread,
Aug 20, 2009, 11:20:28 AM8/20/09
to mpmath
Thank you very much. The patch worked great. Now if could just get
you to write my thesis for me as well. ;-)

~~archery~~

On Aug 20, 7:08 am, Vinzent Steinberg
Reply all
Reply to author
Forward
0 new messages