This is a followup to this SO answer
https://stackoverflow.com/a/71185257/3259896
Moreover, note that mean is not very optimized for such a case. It is faster to use (a[b[:,0]] + a[b[:,1]]) * 0.5 although the intent is less clear.
This is further elaborated in the comments
mean is optimized for 2 cases: the computation of the mean of contiguous lines along the last contiguous axis OR the computation of the mean of many long contiguous lines along a non-contiguous axis.
I looked up contiguous arrays and found it explained here
What is the difference between contiguous and non-contiguous arrays?
It means stored in unbroken blocks of memory.
However, it is still not clear to me if there's any solid cases where I should use mean
over just performing the calculations in python.
I would love to have some solid examples of where and when to use each type of operation.