Skip to content Skip to sidebar Skip to footer

How To Select A Submatrix From An Adjacency List In Python?

I have an adjacency list where each array represents non-zero columns at that row (e.g. 0th array in the adj. list below means columns 2 and 6 are 1, and everything else is 0). ad

Solution 1:

adj_list = [[2, 6], [1, 3, 24], [2, 4], [3, 5, 21], [4, 6, 10], [1, 5, 7], [6, 8, 9], [7], [7, 10, 14], [5, 9, 11], [10, 12, 18], [11, 13], [12, 14, 15], [9, 13], [13, 16, 17], [15], [15], [11, 19, 20], [18], [18], [4, 22, 23], [21], [21], [2, 25, 26], [24], [24]]

submatrix = (0, 1, 2, 5, 22)

result = [[i in adj_list[sm] for i in submatrix] for sm in submatrix]

This should do it; though I suspect you might prefer to compute something other than this if you consider your end goal more carefully.


Post a Comment for "How To Select A Submatrix From An Adjacency List In Python?"