<s> import numpy as np <EOL> def top_n ( score_matrix , n , excludes = [ ] , keep_order = False ) : <EOL> '''<STR_LIT>''' <EOL> score_array = np . squeeze ( np . asarray ( score_matrix ) ) <EOL> score_array [ excludes ] = - <NUM_LIT> <EOL> if not keep_order : <EOL> top_n_indexes = score_array . argsort ( ) [ : : - <NUM_LIT:1> ] [ : n ] . tolist ( ) <EOL> else : <EOL> reversed_scores = ( - <NUM_LIT:1> ) * score_array <EOL> top_n_indexes = list ( zip ( * sorted ( zip ( reversed_scores , range ( len ( reversed_scores ) ) ) , key = lambda a : a [ <NUM_LIT:0> ] ) ) [ <NUM_LIT:1> ] [ : n ] ) <EOL> return zip ( top_n_indexes , score_array [ top_n_indexes ] ) <EOL> def top_ns ( score_matrix , n , excludes = None , keep_order = False ) : <EOL> '''<STR_LIT>''' <EOL> excludes = excludes if excludes else [ [ ] , ] * len ( score_matrix ) <EOL> return [ top_n ( sa , n , excludes = ex , keep_order = keep_order ) for ( sa , ex ) in zip ( score_matrix , excludes ) ] </s>
