In the end, you have to do 1000 computations one way or another.  Generally, 
implicit maps are faster than for loops in Python, so maybe three nested map() 
functions would be faster.  

Also, it would depend on what the expression is, but in some cases you might be 
able to get faster results by changing the order of substitution.  For example, 
if you wanted to map 0, 1, and 2 onto x, y and z in x*y*z, you should first 
substitute x for each number, then y, then z, because as soon as you do the 
first substitute for 0, the expression will vanish and the substitutions for y 
and z will be trivial.  If anything can make the expression evaluate simpler 
like this, you would want it in the outer loop so sympy only has to evaluate 
the simpler version once.

Maybe someone else here will have a more exact solution for you though.

Aaron Meurer
On Dec 4, 2009, at 12:02 PM, wflynny wrote:

> Hi!
> 
> For my current project, I start with a pretty complicated symbolic
> expression that I want to numerically evaluate for different values of
> different variables. Say I have an expression
> 
> expr(x,y,z) = A*x+B*y*z+DiracDelta(x-y+z)+...
> 
> and an array of numerical values for each variable, x,y,z:
> 
> x = np.array([1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0])
> y = np.array([0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0])
> z = np.array([1.0,1.5,2.0,2.5,3.0,3.5,4.0,4.5,5.0,5.5]).
> 
> Currently I want to evaluate expr(x,y,z) for each combination of
> x,y,z, which yields an array of 1000 numerical values of expr, in this
> example. This means a set of for loops scanning over all 1000
> combinations. My question:
> 
> Is there is an easier (less-cpu-cycles-) way to do this kind of mass
> substitution in sympy?
> 
> Can we map in an efficient way to do this? Our problem is that we want
> to evaluate our expression at tens of thousands of points and the for
> loops just eat up too much time.
> 
> Any suggestions would be greatly appreciated!
> 
> Bill
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to 
> sympy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sympy?hl=en.
> 
> 

--

You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sy...@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.


Reply via email to