Form a edge list from a matrix-python -


I have a matrix that looks like the following:

  matrix = [[ 0, 0,1], [1,0,1], [0,1,0]]  

I want to create an edge list that looks like the following:

  Edge_list = {0: [2], 1: [0, 2], 2: [1]}  

The first column nodes in the Edge_list and the next column Identify those nodes that have the edge (matrix value of 1).

Any help would be appreciated. Thank you.

and with:

  & gt; & Gt; & Gt; Matrix = [... [0,0,1], ... [1,0,1], ... [0,1,0], ...]> gt; & Gt; & Gt; & Gt; & Gt; & Gt; {I: [For J, for enumerate x] I, enumerate the row (matrix)} {0: [2], 1: [0, 2], 2: [1] }  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -