[Numpy-discussion] Fromfunction generalization
lorenzo bolla
lbolla at gmail.com
Tue Apr 22 14:50:53 EDT 2008
what about using lambda functions?
M=fromfunction(lambda i,j:f(i,j,5),(1000,1000))
P=fromfunction(lambda i,j:f(i,j,7),(1000,1000))
L.
On Tue, Apr 22, 2008 at 8:42 PM, Gnata Xavier <xavier.gnata at gmail.com>
wrote:
> Hi,
>
> fromfunction is fine but I have like to be able to create 2Darrays using
> a function of i,j but also of one (or more) parameters.
> Something like that :
>
> def f(i,j,a):
> return (i+j)*a #replace that by another non trivial computation
>
> M=fromfunction(f( hum well something like i,j,a),(1000,1000))
>
> this only way I know is to use global :
>
> a=5
>
> def f(i,j):
> global a
> return (i+j)*a
>
> M=fromfunction(f,(1000,1000))
> a=7
> P=fromfunction(f,(1000,1000))
>
> but it is quite ugly :(
>
> Is there a clean and *fast* way to do that ?
>
> Xavier
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
--
Lorenzo Bolla
lbolla at gmail.com
http://lorenzobolla.emurse.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20080422/8ca571d9/attachment.html>
More information about the NumPy-Discussion
mailing list