[MATRIX-SIG] Printing BUG?

David J. C. Beach beach@verinet.com
Fri, 03 Oct 1997 17:04:21 -0600


To he that hath knowlege of the array-printing code...

I believe I've found a bug in NumPy involving its formatting and
printing of arrays,  here's a very simple example of how to recreate the
bug:

-----------------------------------------------------
Python 1.4 (Oct  3 1997)  [GCC 2.7.2.2.f.2]
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from Numeric import *
>>> x = array([[1.496e11, 0, 0], [0, -2.925e4, 0]], Float)
>>> print x
[[  1.49600000e+11   0.00000000e+00   0.00000000e+00]
 [  0.00000000e+00  -2.92500000e+04   0.00000000e+00]]
>>> print x[0]

Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "/usr/local/lib/python1.4/NumPy/Numeric.py", line 116, in
array_str
    return array2string(a, max_line_width, precision, suppress_small, '
', 0)
  File "/usr/local/lib/python1.4/NumPy/ArrayPrinter.py", line 46, in
array2string
    format, item_length = _floatFormat(data, precision, suppress_small)
  File "/usr/local/lib/python1.4/NumPy/ArrayPrinter.py", line 118, in
_floatFormat
    max_str_len = len(str(int(max_val))) + precision + 2
OverflowError: float too large to convert
------------------------------------------------------

I really don't know much about the printing code, but it doesn't seem
that 1.49e+11 should be too large of a number to be converted (to a
string, I assume).  And besides, why does it work when I print x, and
not when I print x[0]?

Anyhow, this bug is creating problems for me because I'm working with,
well, astronomical numbers (no pun), and sometimes when I evaluate
certain arrays or portions of them, I get the OverflowError shown here.

Does anybody else have this problem?  Is there an easy workaround for
this?  (Other than simply never printing arrays?)

Thanks.

Dave

--
David J. C. Beach
Colorado State University
mailto:beach@verinet.com
http://www.verinet.com/~beach




_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________