scipy.stats.itemfreq

scipy.stats.itemfreq(a)[source]

Returns a 2D array of item frequencies.

Parameters :

a : array_like of rank 1

Input array.

Returns :

itemfreq : ndarray of rank 2

A 2D frequency table (col [0:n-1]=scores, col n=frequencies). Column 1 contains item values, column 2 contains their respective counts.

Notes

This uses a loop that is only reasonably fast if the number of unique elements is not large. For integers, numpy.bincount is much faster. This function currently does not support strings or multi-dimensional scores.

Examples

>>> a = np.array([1, 1, 5, 0, 1, 2, 2, 0, 1, 4])
>>> stats.itemfreq(a)
array([[ 0.,  2.],
       [ 1.,  4.],
       [ 2.,  2.],
       [ 4.,  1.],
       [ 5.,  1.]])
>>> np.bincount(a)
array([2, 4, 2, 0, 1, 1])
>>> stats.itemfreq(a/10.)
array([[ 0. ,  2. ],
       [ 0.1,  4. ],
       [ 0.2,  2. ],
       [ 0.4,  1. ],
       [ 0.5,  1. ]])

Previous topic

scipy.stats.normaltest

Next topic

scipy.stats.scoreatpercentile