[Numpy-discussion] Fromfunction generalization

Gnata Xavier xavier.gnata@gmail....
Tue Apr 22 13:42:21 CDT 2008


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


More information about the Numpy-discussion mailing list