I didn't know about ``np.bincount``, and it's almost exactly what I want, except that the classes are arbitrary and not just integers. I could ``LabelEncoder`` them first, but that should be slower than a proper ``_histogram`` implementation?