I have a 2d matrix with a very large dimension (~10000 x 10000) I want to find the frequency of the most common number in each row, and select the row that has the least frequency.
For example, if my 2d array is
[1, 2, 3, 3, 5]
[1, 1, 1, 2, 1]
[3, 2, 2, 1, 3]
[4, 5, 1, 2, 2]
[3, 5, 6, 7, 8]
,
The frequency of most common number in each row is [2, 4, 2, 2, 1]
.
I want to find the index 4 (the last row) because the frequency of most common items is 1, which is the lowest among all rows.
Right now I am just using for loops but is there a vectorized approach that is very fast?
Thank you in advance.