I have created a test example for the question using for loop and hope someone can help me to get fast solution. My data set is about 2000000 data.
 
However, I have the problem to run the code, the Out[i]=cnstl[j] line gives me error says:
 
In [107]: Out[0]=cnstl[0]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
C:\Frank_share\qamslicer.py in <module>()
----> 1
      2
      3
      4
      5
TypeError: can't convert complex to float; use abs(z)
In [108]: cnstl.dtype
Out[108]: dtype('complex128')

I do not know why that my data is complex128 already. Can anyone help to figure why?
 
Thanks
 
Frank
 
from numpy import *
a = arange(-15,16,2)
cnstl=a.reshape(16,1)+1j*a
cnstl=cnstl.reshape(256,1)
X = array([1.4 + 1j*2.7, -4.9 + 1j*8.3])
Out = array(X)
error =array(X)
for i in xrange(2):
    for j in xrange(256):
        a0 = real(X[i]) < (real(cnstl[j])+1)
        a1 = real(X[i]) > (real(cnstl[j])-1)
        a2 = imag(X[i]) > (imag(cnstl[j])-1)
        a3 = imag(X[i]) < (imag(cnstl[j])+1)
 if (a0 & a1 & a2 &a3):
            Out[i] = cnstl[j]
            error[i] = X[i] - cnstl[j]



From: f.yw@hotmail.com
To: numpy-discussion@scipy.org
Subject: RE: [Numpy-discussion] help on fast slicing on a grid
Date: Wed, 28 Jan 2009 23:28:47 -0700

Hi, Bob,
 
Thanks for your help.
 
I am sorry for my type error. qam array is the X array in my example.
 
cntl is a complex array contains the point (x,y) axises.
 
I will try to make a workable example. Also I will try to find out the zeros_like function. However, I guess that zeros_like(X) will create an array the same size as X. It it is. Then the two line Out=X and error=X should be Out=zeros_like(X) and error=zeros(X).
 
Also, can where command handel the logic command?
 
aa = np.where((real(X)<real(cnstl[j])+1) & (real(X)>real(cnstl[j])-1) & (imag(X)<imag(cnstl[j])+1) & (imag(X)>imag(cnstl[j]-1))
 
For example, cntl[j]=3+1j*5, then the where command is the same as:

 
aa = np.where((real(X)<4) & (real(X)>2 )& (imag(X)<6) & (imag(X)>4))
 
Thanks
 
Frank

> Date: Thu, 29 Jan 2009 00:15:48 -0600
> From: robert.kern@gmail.com
> To: numpy-discussion@scipy.org
> Subject: Re: [Numpy-discussion] help on fast slicing on a grid
>
> On Thu, Jan 29, 2009 at 00:09, frank wang <f.yw@hotmail.com> wrote:
> > Here is the for loop that I am think about. Also, I do not know whether the
> > where commands can handle the complicated logic.
> > The where command basically find the data in the square around the point
> > cnstl[j].
>
> cnstl is a 2D array from your previous description.
>
> > Let the data array is qam with size N
>
> I don't see qam anywhere. Did you mean X?
>
> > Out = X
> > error = X
>
> Don't you want something like zeros_like(X) for these?
>
> > for i in arange(N):
> > for j in arange(L):
> > aa = np.where((real(X)<real(cnstl[j])+1) &
> > (real(X)>real(cnstl[j])-1) & (imag(X)<imag(cnstl[j])+1) &
> > (imag(X)>imag(cnstl[j]-1))
> > Out[aa]=cnstl[j]
> > error[aa]=abs(X)**2 - abs(cnstl[j])**2
>
> I'm still confused. Can you show me a complete, working script with
> possibly fake data?
>
> --
> 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@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion



Windows Live™: E-mail. Chat. Share. Get more ways to connect. Check it out.


Hotmail® goes where you go. On a PC, on the Web, on your phone. See how.