[Numpy-discussion] help on fast slicing on a grid

frank wang f.yw at hotmail.com
Sat Jan 31 02:26:25 EST 2009


Hi, Bob,
 
Thanks. This solution works great. It really helps me a lot. 
 
Frank> Date: Fri, 30 Jan 2009 23:08:35 -0600> From: robert.kern at gmail.com> To: numpy-discussion at scipy.org> Subject: Re: [Numpy-discussion] help on fast slicing on a grid> > On Fri, Jan 30, 2009 at 22:41, frank wang <f.yw at hotmail.com> 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 [22]: out> >> Out[22]: array([ 1.+3.j, -5.+9.j])> >>> >> In [23]: error> >> Out[23]: 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> Numpy-discussion at scipy.org> http://projects.scipy.org/mailman/listinfo/numpy-discussion
_________________________________________________________________
Windows Live™ Hotmail®:…more than just e-mail. 
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_explore_012009
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090131/4c690031/attachment.html>


More information about the NumPy-Discussion mailing list