MergePlanner.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:bnpy 作者: bnpy 项目源码 文件源码
def _scorematrix2rankedlist_greedy(M, nPairs, doKeepZeros=False):
    ''' Return the nPairs highest-ranked pairs in score matrix M

        Args
        -------
          M : score matrix, K x K
              should have only entries kA,kB where kA <= kB

        Returns
        --------
          aList : list of integer ids for rows of M
          bList : list of integer ids for cols of M

        Example
        ---------
        _scorematrix2rankedlist( [0 2 3], [0 0 1], [0 0 0], 3)
        >> [ (0,2), (0,1), (1,2)]
    '''
    M = M.copy()
    M[np.tril_indices(M.shape[0])] = - np.inf
    Mflat = M.flatten()
    sortIDs = np.argsort(-1 * Mflat)
    # Remove any entries that are -Inf
    sortIDs = sortIDs[Mflat[sortIDs] != -np.inf]
    if not doKeepZeros:
        # Remove any entries that are zero
        sortIDs = sortIDs[Mflat[sortIDs] != 0]
    bestrs, bestcs = np.unravel_index(sortIDs, M.shape)
    return bestrs[:nPairs].tolist(), bestcs[:nPairs].tolist()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号