I have a matrix like this in NumPy:
array([[0, 0, 1, 1],
[1, 1, 0, 2],
[0, 0, 1, 0],
[0, 2, 1, 1],
[1, 1, 1, 0],
[1, 0, 2, 2]])
I'd like to get the most common value per row. In other words, I'd like to get a vector like this:
array([0, 1, 0, 1, 1, 2])
I managed to solve this problem using Scipy's mode method, in the following way:
scipy.stats.mode(data, axis=1)[0].flatten()
However, I'm looking for a solution which uses NumPy only. Moreover, the solution needs to work with negative integer values as well