I\'m searching for an efficient way to create a matrix of occurrences from two arrays that contains indexes, one represents the row indexes in this matrix,
Use np.add.at, specifying a tuple of indices:
np.add.at
>>> np.add.at(new_matrix, (rows, columns), 1) >>> new_matrix array([[ 1., 0., 0.], [ 0., 2., 0.], [ 0., 1., 2.], [ 2., 1., 5.]])
np.add.at operates on the array in-place, adding 1 as many times to the indices as specified by the (row, columns) tuple.
1
(row, columns)