I have an array of points in 3D. I want to do something close to what np.histogramdd does, but instead of the count of number of points in each bin, I want to return the actual coordinates of the point(s) therein: zeros if there are none, exact xyz if there is just one, and an xyz average if there are two or more, in the order specified by the bins. Should I just modify the source code for histogramdd accordingly, or perhaps there's a quicker/cleaner way?
Asked
Active
Viewed 139 times
1 Answers
1
Here is a recipe:
- Use
np.digitize
to obtain bin indices for each coordinate of each point - Use
np.ravel_multi_index
to transform to flat bin indices - Finally,
- either use this post to group points by bin
- or use
np.bincount
to get the bin counts and, using the optional second argument, to sum coordinates per bin

Paul Panzer
- 51,835
- 3
- 54
- 99
-
Thanks a bunch! Will post what I got. – Roman Sep 17 '19 at 19:56