Given:
>>> import numpy as np
>>> LoL = [[2,4,1,6,3], [2,4,1,8,4], [6,5,4,3,2], [6,5,4,3,4], [1,2,3,4,5]]
>>> matrix=np.array(LoL)
>>> matrix
[[2 4 1 6 3]
[2 4 1 8 4]
[6 5 4 3 2]
[6 5 4 3 4]
[1 2 3 4 5]]
You can do:
>>> np.argmax(np.bincount(matrix.flat))
4
Or,
u, c = np.unique(your_lst, return_counts=True)
u[c.argmax()]
# 4
If you wanted to do this without numpy or any import to count the most frequent entry in a list of lists, you can use a dictionary to count each element from a generator that is flattening your list of lists:
cnts={}
for e in (x for sl in LoL for x in sl):
cnts[e]=cnts.get(e, 0)+1
Then sort by most frequent:
>>> sorted(cnts.items(), key=lambda t: t[1], reverse=True)
[(4, 7), (2, 4), (3, 4), (1, 3), (5, 3), (6, 3), (8, 1)]
Or, just use max if you only want the largest:
>>> max(cnts.items(), key=lambda t: t[1])
np.matrix. It's got all sorts of weird compatibility issues, it's deprecated, and people often find that they want the exact opposite of the behavior they asked for by using it.numpy.unique. You can return counts.