Re: How to "reduce" a numpy array using a costum binary function

2008-11-13 Thread Slaunger
On 13 Nov., 22:48, Robert Kern <[EMAIL PROTECTED]> wrote: > Slaunger wrote: > > It is always good to ask yourself a question. > > I had forgooten about the reduce function > > > I guess this implementation > > > from numpy import * > > > def compl_add_uint16(a, b): > >     c = a + b > >     c += c

Re: How to "reduce" a numpy array using a costum binary function

2008-11-13 Thread Robert Kern
Slaunger wrote: It is always good to ask yourself a question. I had forgooten about the reduce function I guess this implementation from numpy import * def compl_add_uint16(a, b): c = a + b c += c >> 16 return c & 0x def compl_one_checksum(uint16s): return reduce(compl_add

Re: How to "reduce" a numpy array using a costum binary function

2008-11-13 Thread Slaunger
It is always good to ask yourself a question. I had forgooten about the reduce function I guess this implementation from numpy import * def compl_add_uint16(a, b): c = a + b c += c >> 16 return c & 0x def compl_one_checksum(uint16s): return reduce(compl_add_uint16, uint16s,

How to "reduce" a numpy array using a costum binary function

2008-11-13 Thread Slaunger
I know there must be a simple method to do this. I have implemented this function for calculating a checksum based on a ones complement addition: def complement_ones_checksum(ints): """ Returns a complements one checksum based on a specified numpy.array of dtype=uint16 """ res