0

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?

Roman
  • 129
  • 1
  • 9

1 Answers1

1

Here is a recipe:

  1. Use np.digitize to obtain bin indices for each coordinate of each point
  2. Use np.ravel_multi_index to transform to flat bin indices
  3. Finally,
    1. either use this post to group points by bin
    2. 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