Briefly: there is a similar question and the best answer suggests using numpy.bincount. I need the same thing, but for a matrix.
numpy.bincount
I\'ve got two arrays:>
m1 = m.view(numpy.ndarray) # Create view m1.shape = -1 # Make one-dimensional array m1 += np.bincount(a+m.shape[1]*b, minlength=m1.size)