[SciPy-User] Avoiding lambda functions
David MacQuigg
macquigg@ece.arizona....
Mon Oct 18 19:08:46 CDT 2010
> Reply to all.
Many thanks to Robert and Zachary. I see now we don't even need the
gaussianfilter function. We can just use gauss directly. Code modifications
below.
Thanks also to Stefan. I'll check out py4science.
> from numpy import exp, indices # numpy package from scipy.org
> img0 = imread('Lena.pgm') # a 200 by 200 greyscale image
> shape = img0.shape # (200, 200)
>
> def gauss(i,j,sigma,shape): # a 2D gaussian function
> x = -1.0 + 2.0*i/shape[0]
> y = -1.0 + 2.0*j/shape[1]
> return exp(-(x*x+y*y)/(2*sigma*sigma))
iray, jray = indices(shape)
filter = gauss(iray, jray, 0.1, shape)
More information about the SciPy-User
mailing list