#NEWLINE# def count_tied_groups( x , use_missing = False ) : #NEWLINE# #INDENT# '\n    Counts the number of tied values.\n\n    Parameters\n    ----------\n    x : sequence\n        Sequence of data on which to counts the ties\n    use_missing : bool, optional\n        Whether to consider missing values as tied.\n\n    Returns\n    -------\n    count_tied_groups : dict\n        Returns a dictionary (nb of ties: nb of groups).\n\n    Examples\n    --------\n    >>> from scipy.stats import mstats\n    >>> z = [0, 0, 0, 2, 2, 2, 3, 3, 4, 5, 6]\n    >>> mstats.count_tied_groups(z)\n    {2: 1, 3: 2}\n\n    In the above example, the ties were 0 (3x), 2 (3x) and 3 (2x).\n\n    >>> z = np.ma.array([0, 0, 1, 2, 2, 2, 3, 3, 4, 5, 6])\n    >>> mstats.count_tied_groups(z)\n    {2: 2, 3: 1}\n    >>> z[[1,-1]] = np.ma.masked\n    >>> mstats.count_tied_groups(z, use_missing=True)\n    {2: 2, 3: 1}\n\n    ' #NEWLINE# nmasked = ma . getmask ( x ) . sum ( ) #NEWLINE# data = ma . compressed ( x ) . copy ( ) #NEWLINE# ( ties , counts ) = find_repeats ( data ) #NEWLINE# nties = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if len ( ties ) : #NEWLINE# #INDENT# nties = dict ( zip ( np . unique ( counts ) , itertools . repeat ( 1 ) ) ) #NEWLINE# nties . update ( dict ( zip ( * find_repeats ( counts ) ) ) ) #NEWLINE# #UNINDENT# if ( nmasked and use_missing ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# nties [ nmasked ] += 1 #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# nties [ nmasked ] = 1 #NEWLINE# #UNINDENT# #UNINDENT# return nties