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

Slaunger Slaunger at gmail.com
Thu Nov 13 06:48:38 EST 2008


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
    """
    result = 0x0
    for i in ints:
        result += i
        result = (result  + (result >> 16)) & 0xFFFF
    return result

It works, but is of course inefficient. My prfiler syas this is the
99.9% botteleneck in my applicaiton.

What is the efficient numpy way to do this?

No need to dwelve into fast inlining of c-code or Fortran and stuff
like that although that may give further performance imporevements.



More information about the Python-list mailing list