Suppose I have
data =
[[a, a, c],
[b, c, c],
[c, b, b],
[b, a, c]]
I want to get a list containing the element that occurs the most in each
In statistics, what you want is called the mode. The scipy library (http://www.scipy.org/) has a mode
function, in scipy.stats
.
In [32]: import numpy as np
In [33]: from scipy.stats import mode
In [34]: data = np.random.randint(1,6, size=(6,8))
In [35]: data
Out[35]:
array([[2, 1, 5, 5, 3, 3, 1, 4],
[5, 3, 2, 2, 5, 2, 5, 3],
[2, 2, 5, 3, 3, 2, 1, 1],
[2, 4, 1, 5, 4, 4, 4, 5],
[4, 4, 5, 5, 2, 4, 4, 4],
[2, 4, 1, 1, 3, 3, 1, 3]])
In [36]: val, count = mode(data, axis=0)
In [37]: val
Out[37]: array([[ 2., 4., 5., 5., 3., 2., 1., 3.]])
In [38]: count
Out[38]: array([[ 4., 3., 3., 3., 3., 2., 3., 2.]])