I have a numpy matrix A
, for example
3 4 3 4
2 1 3 5
3 2 1 1
1 1 1 1
I want to count occurances PER ROW, knowing the data in each cell comes from a given "possible votes" array, for example [0, 1, 2, 3, 4, 5, 6]
,
In this case I would like an output which has the same number of rows, and a column for every possible "vote", meaning something like
(0) (1) (2) (3) (4) (5) (6)
0 0 0 2 2 0 0
0 1 1 1 0 1 0
0 2 1 1 0 0 0
0 4 0 0 0 0 0
How can this be accomplished with numpy? Runtime is important.
This smells like np.bincount
, but I can't figure out how to efficiently generalize to a higher dimension.