def aharmonicmean (inarray,dimension=None,keepdims=0):
    inarray = inarray.astype(N.float_)
    if dimension == None:
        inarray = N.ravel(inarray)
        size = len(inarray)
        s = N.add.reduce(1.0 / inarray)
    elif type(dimension) in [IntType,FloatType]:
        size = float(inarray.shape[dimension])
        s = N.add.reduce(1.0/inarray, dimension)
        if keepdims == 1:
            shp = list(inarray.shape)
            shp[dimension] = 1
            s = N.reshape(s,shp)
    else: # must be a SEQUENCE of dims to average over
        dims = list(dimension)
        dims.sort()
        nondims = []
        for i in range(len(inarray.shape)):
            if i not in dims:
                nondims.append(i)
        tinarray = N.transpose(inarray,nondims+dims) # put keep-dims first
        idx = [0] *len(nondims)
        if idx == []:
            size = len(N.ravel(inarray))
            s = asum(1.0 / inarray)
            if keepdims == 1:
                s = N.reshape([s],N.ones(len(inarray.shape)))
        else:
            idx[0] = -1
            loopcap = N.array(tinarray.shape[0:len(nondims)]) -1
            s = N.zeros(loopcap+1,N.float_)
            while incr(idx,loopcap) <> -1:
                s[idx] = asum(1.0/tinarray[idx])
            size = N.multiply.reduce(N.take(inarray.shape,dims))
            if keepdims == 1:
                shp = list(inarray.shape)
                for dim in dims:
                    shp[dim] = 1
                s = N.reshape(s,shp)
    return size / s
Calculates the harmonic mean of the values in the passed array.
dataset/ETHPy150Open radlab/sparrow/src/main/python/third_party/stats.py/aharmonicmean