'Parameters
target_ids: array of shape [n_target_ids]
source_id: int or string
item id to compare against.
how_many: int
Desired number of most top items to recommend (default=None ALL)
Returns
Return the top N matches
It can be user_ids or item_ids.'

def _top_matches(self, source_id, target_ids, how_many=None, **params):

    if (target_ids.size == 0):
        return np.array([])
    estimate_preferences = np.vectorize(self.estimate_preference)
    preferences = estimate_preferences(source_id, target_ids)
    preferences = preferences[(~ np.isnan(preferences))]
    target_ids = target_ids[(~ np.isnan(preferences))]
    sorted_preferences = np.lexsort((preferences,))[::(-1)]
    sorted_preferences = (sorted_preferences[0:how_many] if (how_many and (sorted_preferences.size > how_many)) else sorted_preferences)
    if self.with_preference:
        top_n_recs = [(target_ids[ind], preferences[ind]) for ind in sorted_preferences]
    else:
        top_n_recs = [target_ids[ind] for ind in sorted_preferences]
    return top_n_recs
