[MATRIX-SIG] ArrayPrinter problem

Jeffery D. Collins jcollins@pacificnet.net
Fri, 30 Jan 1998 19:40:39 -0800


There seems to be a problem in the ArrayPrinter module.  Consider
the following:

>>> from Numeric import array
>>>
>>>
>>> a = array((1e9,))
>>> a
array([ 1000000000.])
>>> str(a)
'[ 1000000000.]'
>>> str( array((1e9,)) )
'[ 1000000000.]'
>>> str( array((1e10,)) )
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "/usr/local/Python1.5/lib/python1.5/Numeric.py", line 116, in
array_str
    return array2string(a, max_line_width, precision, suppress_small, '
', 0)
  File "/usr/local/Python1.5/lib/python1.5/ArrayPrinter.py", line 46, in
array2string
    format, item_length = _floatFormat(data, precision, suppress_small)
  File "/usr/local/Python1.5/lib/python1.5/ArrayPrinter.py", line 118,
in _floatFormat
    max_str_len = len(str(int(max_val))) + precision + 2
OverflowError: float too large to convert
>>> str( array((1e12,)) )
'[  1.00000000e+12]'


Apparently, the max_val is exceeding MAX_INT in the expression
    max_str_len = len(str(int(max_val))) + precision + 2

I was able to fix the problem by replacing (line 101)

  if max_val >= 1.e12:
   exp_format = 1

with

  if max_val >= 1.e9:
   exp_format = 1


Now:
>>> from Numeric import array
>>> str( array((1e8,)) )
'[ 100000000.]'
>>> str( array((1e9,)) )
'[  1.00000000e+09]'
>>> str( array((1e10,)) )
'[  1.00000000e+10]'
>>> str( array((1e11,)) )
'[  1.00000000e+11]'
>>> str( array((1e12,)) )
'[  1.00000000e+12]'
>>> str( array((1e30,)) )
'[  1.00000000e+30]'

Thanks,

Jeff



_______________
MATRIX-SIG  - SIG on Matrix Math for Python

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