[Numpy-discussion] help on fast slicing on a grid
Fri Jan 30 23:08:35 CST 2009
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
"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
More information about the Numpy-discussion