[SciPy-user] linalg mat - init from string?

Ron Bondy ronbondy at telus.net
Wed Dec 15 15:37:54 EST 2004


I'm new to scipy and am trying to use it to do some tests on a 67X67 unsymmetric matrix.  The matrix is a jacobian calculated in another program and I'm looking for a way to write it out as a python script so that I can import the python script and then manually invert the matrix, calc eigenvalues etc.

I'm having trouble finding a format that I can write the matrix out in.

>From the scipy docs this is how to init a mat:
A = mat('[1 3 5; 2 5 1; 2 3 8]')


As a simple example, suppose that this is the python source:

from scipy import *

bstr = '[ 1 3 5; 2 3 1 ; 3.1 5.1 8.0]'
A = mat(bstr)

when I run this as a python script I get this error:

Traceback (most recent call last):
  File "bb.py", line 8, in ?
    A = mat(bstr)
  File "C:\Python23\Lib\site-packages\scipy_base\ppimport.py", line 115, in __call__
    return self._ppimport_attr(*args,**kwds)
  File "C:\Python23\Lib\site-packages\Numeric\Matrix.py", line 69, in __init__
    data = _convert_from_string(data)
  File "C:\Python23\Lib\site-packages\Numeric\Matrix.py", line 36, in _convert_from_string
    newrow.extend(map(_eval,temp))
  File "C:\Python23\Lib\site-packages\Numeric\Matrix.py", line 24, in _eval
    return eval(astr.translate(_table,_todelete))
  File "<string>", line 0
    
    ^
SyntaxError: unexpected EOF while parsing

why is the parser seeing an EOF?

If someone can explain to me what the problem here is I would appreciate it.  I was hoping to write out the larger matrix as a string and then construct a mat object from the string.

Thanks,

Ron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20041215/fd29d3d1/attachment.html>


More information about the SciPy-User mailing list