python - How to find most occurred element in each row of a multidimentional array? -



python - How to find most occurred element in each row of a multidimentional array? -

suppose have array:

import numpy np a=np.array([[1,0,0,1,0,0,0,1],[1,1,1,1,0,0,1,1]])

how can compute array b occurred values? ie.

b=([[0],[1]])

if have scipy available, utilize scipy.stats.mode:

>>> = np.array([[1,0,0,1,0,0,0,1],[1,1,1,1,0,0,1,1]]) >>> import scipy.stats >>> most, mostcc = scipy.stats.mode(a, axis=1) >>> array([[ 0.], [ 1.]]) >>> mostcc array([[ 5.], [ 6.]])

note, docs:

if there more 1 such value, first returned. bin-count modal bins returned.

python python-2.7

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -