def find_duplicates(a, key=None, ignoremask=True, return_index=False):
a = np.asanyarray(a).ravel()<EOL>fields = get_fieldstructure(a.dtype)<EOL>base = a<EOL>if key:<EOL><INDENT>for f in fields[key]:<EOL><INDENT>base = base[f]<EOL><DEDENT>base = base[key]<EOL><DEDENT>sortidx = base.argsort()<EOL>sortedbase = base[sortidx]<EOL>sorteddata = sortedbase.filled()<EOL>flag = (sorteddata[:-<NUM_LIT:1>] == sorteddata[<NUM_LIT:1>:])<EOL>if ignoremask:<EOL><INDENT>sortedmask = sortedbase.recordmask<EOL>flag[sortedmask[<NUM_LIT:1>:]] = False<EOL><DEDENT>flag = np.concatenate(([False], flag))<EOL>flag[:-<NUM_LIT:1>] = flag[:-<NUM_LIT:1>] + flag[<NUM_LIT:1>:]<EOL>duplicates = a[sortidx][flag]<EOL>if return_index:<EOL><INDENT>return (duplicates, sortidx[flag])<EOL><DEDENT>else:<EOL><INDENT>return duplicates<EOL><DEDENT>
Find the duplicates in a structured array along a given key

Parameters
----------
a : array-like
    Input array
key : {string, None}, optional
    Name of the fields along which to check the duplicates.
    If None, the search is performed by records
ignoremask : {True, False}, optional
    Whether masked data should be discarded or considered as duplicates.
return_index : {False, True}, optional
    Whether to return the indices of the duplicated values.

Examples
--------
>>> from numpy.lib import recfunctions as rfn
>>> ndtype = [('a', int)]
>>> a = np.ma.array([1, 1, 1, 2, 2, 3, 3],
...         mask=[0, 0, 1, 0, 0, 0, 1]).view(ndtype)
>>> rfn.find_duplicates(a, ignoremask=True, return_index=True)
... # XXX: judging by the output, the ignoremask flag has no effect