[SciPy-User] Filling a function with values
Jose Gomez-Dans
jgomezdans@gmail....
Fri Jul 31 11:59:51 CDT 2009
Hi,
This is a really quick and stupid question. Let's say I have a function and
I want to calculate its value for a set of points. What's the best way of
quickly doing this avoiding loops?
def MyFunction ( p1, p2, p3, t, y)
return *some_value*
t = numpy.array ( ..... )
y = numpy.array ( ....)
a1,a2,a3 = numpy.mgrid [ 0:100, 0:1:100j, 0:100 ]
evaluated_function = MyFunction (a1, a2, a3, t, y)
evaluated_function.shape would be (100,100,100), and evaluated_function [m,
n, k] should be equal to
MyFunction ( a1[m], a2[n], a3[k], t, y )
I think mgrid (ogrid) are the right tools, but I don't really understand how
I can get it to do what I want. I have read <
http://docs.scipy.org/doc/scipy/reference/tutorial/basic.html#id5>, but that
doesn't clear things up. I guess that what I want to do is just mentioned at
the end of this Section of the tutorial, but can anyone maybe give an
example?
many thanks!
J
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20090731/531d7a0f/attachment.html
More information about the SciPy-User
mailing list