def mode(a, axis=<NUM_LIT:0>):
a, axis = _chk_asarray(a, axis)<EOL>scores = np.unique(np.ravel(a))       <EOL>testshape = list(a.shape)<EOL>testshape[axis] = <NUM_LIT:1><EOL>oldmostfreq = np.zeros(testshape, dtype=a.dtype)<EOL>oldcounts = np.zeros(testshape)<EOL>for score in scores:<EOL><INDENT>template = (a == score)<EOL>counts = np.expand_dims(np.sum(template, axis),axis)<EOL>mostfrequent = np.where(counts > oldcounts, score, oldmostfreq)<EOL>oldcounts = np.maximum(counts, oldcounts)<EOL>oldmostfreq = mostfrequent<EOL><DEDENT>return mostfrequent, oldcounts<EOL>
Returns an array of the modal (most common) value in the passed array.

If there is more than one such value, only the first is returned.
The bin-count for the modal bins is also returned.

Parameters
----------
a : array_like
    n-dimensional array of which to find mode(s).
axis : int, optional
    Axis along which to operate. Default is 0, i.e. the first axis.

Returns
-------
vals : ndarray
    Array of modal values.
counts : ndarray
    Array of counts for each mode.

Examples
--------
>>> a = np.array([[6, 8, 3, 0],
                  [3, 2, 1, 7],
                  [8, 1, 8, 4],
                  [5, 3, 0, 5],
                  [4, 7, 5, 9]])
>>> from scipy import stats
>>> stats.mode(a)
(array([[ 3.,  1.,  0.,  0.]]), array([[ 1.,  1.,  1.,  1.]]))

To get mode of whole array, specify axis=None:

>>> stats.mode(a, axis=None)
(array([ 3.]), array([ 3.]))