plotiterator.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:jiveplot 作者: haavee 项目源码 文件源码
def solint_numpy_countbin(dsref):
    start = time.time()
    dsref.as_numarray()

    # get the unique time stamps 
    tms   = numpy.unique(dsref.x)

    # check if there is something to be averaged at all
    if len(tms)==len(dsref.x):
        return time.time() - start

    # "bins" will be the destination bin where the quantity
    # will be summed into for each unique time stamp
    # i.e. all data having time stamp tms[0] will be summed into
    #      bin 0, all data having time stamp tms[x] will be summed
    #      into bin x
    #bins  = range( len(tms) )
    # Now we must transform the array of times (dsref.x) into an
    # array with bin indices
    dests = reduce(lambda acc, (ix, tm): \
                      numpy.put(acc, numpy.where(dsref.x==tm), ix) or acc, \
                   enumerate(tms), \
                   numpy.empty(dsref.x.shape, dtype=numpy.int32))
    # Good, now that we have that ...
    sums  = numpy.bincount(dests, weights=dsref.y)
    count = numpy.bincount(dests)
    dsref.y = sums/count
    dsref.x = tms
    return time.time() - start
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号