[Numpy-discussion] help on fast slicing on a grid
Sat Jan 31 01:26:25 CST 2009
Thanks. This solution works great. It really helps me a lot.
Frank> Date: Fri, 30 Jan 2009 23:08:35 -0600> From: firstname.lastname@example.org> To: email@example.com> Subject: Re: [Numpy-discussion] help on fast slicing on a grid> > On Fri, Jan 30, 2009 at 22:41, frank wang <firstname.lastname@example.org> wrote:> > Thanks for the correction. I will learn the ravel() function since I do not> > know it. Moving from Matlab world into python is tricky sometime.> >> > Your output> > In : out> >> Out: array([ 1.+3.j, -5.+9.j])> >>> >> In : error> >> Out: array([ 0.4-0.3j, 0.1-0.7j])> >> > are correct answer.> >> > However, if my data set is large, this solution takes long time to run. Are> > there any python/numpy magic to speed it up?> > from numpy import *> > a = arange(-15,16,2)> cnstl = a[:,newaxis] + 1j*a> cnstl = cnstl.ravel()> X = array([1.4 + 1j*2.7, -3.9 + 1j*8.3])> > out = around((X + 1+1j) / 2.0) * 2.0 - (1+1j)> error = X - out> > print out> print error> > -- > Robert Kern> > "I have come to believe that the whole world is an enigma, a harmless> enigma that is made terrible by our own mad attempt to interpret it as> though it had an underlying truth."> -- Umberto Eco> _______________________________________________> Numpy-discussion mailing list> Numpyemail@example.com> http://projects.scipy.org/mailman/listinfo/numpy-discussion
Windows Live™ Hotmail®:…more than just e-mail.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion