scipy.stats.rankdata¶
-
scipy.stats.
rankdata
(a, method='average')[source]¶ Assign ranks to data, dealing with ties appropriately.
Ranks begin at 1. The method argument controls how ranks are assigned to equal values. See [1] for further discussion of ranking methods.
Parameters: - a : array_like
The array of values to be ranked. The array is first flattened.
- method : str, optional
The method used to assign ranks to tied elements. The options are ‘average’, ‘min’, ‘max’, ‘dense’ and ‘ordinal’.
- ‘average’:
The average of the ranks that would have been assigned to all the tied values is assigned to each value.
- ‘min’:
The minimum of the ranks that would have been assigned to all the tied values is assigned to each value. (This is also referred to as “competition” ranking.)
- ‘max’:
The maximum of the ranks that would have been assigned to all the tied values is assigned to each value.
- ‘dense’:
Like ‘min’, but the rank of the next highest element is assigned the rank immediately after those assigned to the tied elements.
- ‘ordinal’:
All values are given a distinct rank, corresponding to the order that the values occur in a.
The default is ‘average’.
Returns: - ranks : ndarray
An array of length equal to the size of a, containing rank scores.
References
[1] (1, 2) “Ranking”, http://en.wikipedia.org/wiki/Ranking Examples
>>> from scipy.stats import rankdata >>> rankdata([0, 2, 3, 2]) array([ 1. , 2.5, 4. , 2.5]) >>> rankdata([0, 2, 3, 2], method='min') array([ 1, 2, 4, 2]) >>> rankdata([0, 2, 3, 2], method='max') array([ 1, 3, 4, 3]) >>> rankdata([0, 2, 3, 2], method='dense') array([ 1, 2, 3, 2]) >>> rankdata([0, 2, 3, 2], method='ordinal') array([ 1, 2, 4, 3])