You can use `numpy.digitize(x, bins)` in order to get the `i` and `j` values for your new map. In fact, this is what used in `np.histogram` internally, I think. This way, you could create both maps (the one with the weights and the one with the counts) in one go.