On 7/2/07, Ryan Krauss <ryanlists at gmail.com> wrote:
> If a matrix is composed of [[A,B,C],[D,E,F]] then the output I need is
> array([[A,B,C],[D,E,F]]).
OK. How about this:
python_matrix (M) := fortran (funmake ('array, [args (M)]));
e.g.
M : matrix ([cos(x)^3, sin(x)^4, tan(y^5)], [sin(y*x)*cos(y),
tan(u*v), u^2*v^2]);
python_matrix (M);
=>
array([[cos(x)**3,sin(x)**4,tan(y**5)],[cos(y)*sin(x*y),tan(u*v),u
1 **2*v**2]])
If you want to direct the output of fortran into a file,
wrap it in with_stdout, e.g.
with_stdout ("/tmp/foo.out", python_matrix (M));
=> (stuff shown above goes into /tmp/foo.out)
The leading "1" on the 2nd line is a continuation character.
I don't know if you want to try to paste together lines.
The program to print stuff in Fortran format is not too complex;
if the Python output can be characterized as a not-too-great
modification of Fortran, I'll help you modify the output of
Maxima's fortran function as needed. Generating Python
output has come up before so maybe a python function
would be useful to others.
FWIW
Robert Dodier