Conversion from numarray to numpy
Some time ago I wrote small lib for signal processing. Now I'm trying to convert it from numarray to numpy, and I've problem: Code in numarray: for i in range(len(myinput)-m+1): cin=tempmatr[:] ctmp=tempmatr[i] xtmp=(numarray.abs(cin-ctmp))<=r x2tmp=numarray.sum(numarray.transpose(xtmp)) mcount=numarray.sum(x2tmp==m) allcount=allcount+mcount Code in numpy: for i in range(len(myinput)-m+1): cin=tempmatr[:] ctmp=tempmatr[i] xtmp=(numpy.abs(cin-ctmp))<=r x2tmp=numpy.sum(numpy.transpose(xtmp)) mcount=numpy.sum(x2tmp==m) allcount=allcount+mcount In numarray line: xtmp=(numarray.abs(cin-ctmp))<=r returns array of ones and zeros, but in numpy xtmp=(numpy.abs(cin-ctmp))<=r returns True/False I would like to know how change this True/False to 1/0 THX -- Mike Szpadzik
On 7/11/07, Michał Szpadzik <mszpadzik@o2.pl> wrote:
I would like to know how change this True/False to 1/0
Multiplying by 1 changes the True/False to 1/0. But sum gives the same result for True/False as it does for 1/0. So maybe you don't need to convert from True/False to 1/0?
Sorry, I made a typo! On Wednesday 11 July 2007 17:32, Eike Welk wrote:
On Wednesday 11 July 2007 12:52, Michał Szpadzik wrote:
I would like to know how change this True/False to 1/0
To convert an array of bool to an array double, you can use the function numpy.doube( ... ). The function numpy.int32( ... ) It should read: numpy.double
converts to integers.
Regards, Eike.
Eike.
THX for help and all answers. Code: for i in range(len(myinput)-m+1): cin=tempmatr[:] ctmp=tempmatr[i] xtmp=((numpy.abs(cin-ctmp))<=r)*1 x2tmp=numpy.sum(numpy.transpose(xtmp), axis=0) mcount=numpy.sum((x2tmp==m)*1) allcount=allcount+mcount works just fine. Now it's time to optimize my lib a little :D Regards
participants (3)
-
Eike Welk -
Keith Goodman -
Michał Szpadzik