This question already has an answer here:
I have two arrays describing a 1-dimensional mass distribution. The first array, $x$, are the (un-sorted, and un-evenly distributed) x-coordinates; the second, $m$, the corresponding masses. I would like to bin the data, and obtain the total masses contained in each bin and plot them out. My question is: how to do that?
I could first get the sorted $x$ array, $x'$, and get the corresponding $m'$, then Do-loop to sum every few $m'$ elements. But it seems a question of weighted histogram, so I guess there might be a simpler solution?