Corresponding scores based on edges of a graph

前端 未结 1 833
后悔当初
后悔当初 2020-12-21 12:50
import numpy as np

score = np.array([
    [0.9, 0.7, 0.2, 0.6, 0.4],
    [0.7, 0.9, 0.6, 0.8, 0.3],
    [0.2, 0.6, 0.9, 0.4, 0.7],
    [0.6, 0.8, 0.4, 0.9, 0.3],
           


        
相关标签:
1条回答
  • 2020-12-21 12:57

    We could convert the list of tuples holding the indices to array and then use slicing or tuple packed ones.

    So, convert to array :

    l2_arr = np.asarray(l2)-1
    

    Then, one way would be -

    score[l2_arr[:,0], l2_arr[:,1]]
    

    Another -

    score[tuple(l2_arr.T)]
    

    For completeness, here's one using a loop-comprehension to extract the row, column indices and thus avoiding any array conversion -

    score[[i[0]-1 for i in l2], [i[1]-1 for i in l2]]
    
    0 讨论(0)
提交回复
热议问题