[SciPy-user] linalg mat - init from string?
pearu at scipy.org
Wed Dec 15 15:15:17 CST 2004
On Wed, 15 Dec 2004, Ron Bondy wrote:
> 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
> 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.
The problem is that you have one extra space after `[' in bstr.
bstr = '[1 3 5; 2 3 1 ; 3.1 5.1 8.0]'
Similar EOF problem will occur when there would be space before `]`.
I'd say its a Numeric bug.
More information about the SciPy-user