Solved by tom in post #2 
              
              
                I’d look at the third-party package PyTorch scatter. It has a reduction=mean mode. 
You need to convert lst to a tensor and possibly use broadcasting. 
Now, the scatter implementation uses atomics, which is problematic e.g. in terms of performance. If the partitions are ordered (as your example sugg…