In short: there is a similar question, and the best answer involves using numpy.bincount . I need the same thing, but for the matrix.
I have two arrays:
array([1, 2, 1, 1, 2]) array([2, 1, 1, 1, 1])
together they create indexes that need to be increased:
>>> np.array([a, b]).T array([[1, 2], [2, 1], [1, 1], [1, 1], [2, 1]])
I want to get this matrix:
array([[0, 0, 0], [0, 2, 1], # (1,1) twice, (1,2) once [0, 2, 0]]) # (2,1) twice
The matrix will be small (for example, 5 ร 5), and the number of indices will be large (somewhere around 10 ^ 3 or 10 ^ 5).
So, is there anything better (faster) than for -loop?