Numpy: Average of values corresponding to unique coordinate positions

前端 未结 4 1433
误落风尘
误落风尘 2021-01-02 05:15

So, I have been browsing stackoverflow for quite some time now, but I can\'t seem to find the solution for my problem

Consider this

import numpy as n         


        
4条回答
  •  一生所求
    2021-01-02 05:39

    This is a simple one-liner using the numpy_indexed package (disclaimer: I am its author):

    import numpy_indexed as npi
    unique, mean = npi.group_by(coo).mean(values)
    

    Should be comparable to the currently accepted answer in performance, as it does similar things under the hood; but all in a well tested package with a nice interface.

提交回复
热议问题