#NEWLINE# def xmatch( a , b ) : #NEWLINE# #INDENT# 'Match two lists of bubble locations\n\n    The matches are constrained to be one-to-one or\n    0-to-one. There are no many-to-one matches\n\n    Matching happens greedily -- each pair of\n    un-matched closest bubbles are matched, until\n    no more matches are possible\n\n\n    Parameters\n    ----------\n    a : list of stamp params\n        Each param is a tuple of the form (lon_field, lon, lat, radius)\n\n    b : list of stamp params\n        like a\n\n    These stamp params are returned by, e.g., Field.all_stamps\n    or bubbly.dr1.bubble_params()\n\n    Returns\n    -------\n    match : array of ints\n        Each element lists which item in b matches to each item in a,\n        or -1 if no match is found\n    ' #NEWLINE# a = np . asarray ( a ) #NEWLINE# b = np . asarray ( b ) #NEWLINE# d = bubble_distance_matrix ( a , b ) #NEWLINE# result = ( np . zeros ( a . shape [ 0 ] , dtype = np . int ) - 1 ) #NEWLINE# while np . isfinite ( d ) . any ( ) : #NEWLINE# #INDENT# best = np . argmin ( d ) #NEWLINE# ( i , j ) = np . unravel_index ( best , d . shape ) #NEWLINE# result [ i ] = j #NEWLINE# d [ i , : ] = np . inf #NEWLINE# d [ : , j ] = np . inf #NEWLINE# #UNINDENT# return result