# [PYTHON MATRIX-SIG] Speed...cg...and more!

Thomas Schwaller et@appl-math.tu-muenchen.de
Mon, 13 Nov 1995 15:40:36 +0100

```Sorry for the typos in my last message. Here are some other things I forgot
there.
1) What about a Matrix constructor which can use constant values and
functions for initailising.
e.g.

from math import *
from Matrix import *

f=lambda i, j: sin(i)*cos(j)
a=Matrix(1000,1000, func=f)  #square 1000x1000 matrix
b=a=Matrix_d(10,10,10, func=lambda i, j, k: sin(i)*cos(j)*exp(k)
#10x10x10 tensor

If we do that in the standard way it will not be fast enough. I nearly
always
have this problem when using some procedure which need functions as input.
I C-code it's no problem at all and after introducing it in python it's
just to slow (e.g. minimize a function...). Imagine that the function is
evaluated 100000 times! What to do. If we could compile simple functions
on the fly this would be just fine. Not a general Python Compiler, but
just a tiny one for certain things.
(interactivity is lost a little bit)
Or write some new module for that type of work (Some Parser thigs!)
The above example would go as
b=Matrix(1000,1000, "sin(i)*cos(j)")
or Matrix(1000,1000, "i,j->sin(i)*cos(j)")

Tom

=================
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org