Numpy: Mode function for ndarray

Created on 19 Jan 2017  路  2Comments  路  Source: numpy/numpy

I was wondering if there was any particular reason as to why there doesn't exist a mode function like the mean and median functions that work on ndarray. I feel that it should be provided.
( On that note, if I wanted to contribute this function to numpy then what would be a good starting point for me?)
Thanks in advance

Most helpful comment

That doesn't make sense to me, since it is something that can be computed from functions already implemented in NumPy, and it's not nice to add Scipy as a dependency in a project just for a couple of methods not covered by NumPy. However, a workaround (at least for 1D arrays of ints) for this could be just np.argmax(np.bincount(array)) (extracted from https://stackoverflow.com/a/6252400).

All 2 comments

There's scipy.stats.mode which should do what you want. Mode is much less common than mean/median, so we won't move that into NumPy.

That doesn't make sense to me, since it is something that can be computed from functions already implemented in NumPy, and it's not nice to add Scipy as a dependency in a project just for a couple of methods not covered by NumPy. However, a workaround (at least for 1D arrays of ints) for this could be just np.argmax(np.bincount(array)) (extracted from https://stackoverflow.com/a/6252400).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

keithbriggs picture keithbriggs  路  3Comments

MorBilly picture MorBilly  路  4Comments

Kreol64 picture Kreol64  路  3Comments

dmvianna picture dmvianna  路  4Comments

perezpaya picture perezpaya  路  4Comments