0
$\begingroup$

I have an adjacency matrix obtained by:

n1=4;
f[i_, j_] := If[j > 1, RandomInteger[], RandomInteger[]];
s1 = SparseArray[{{i_, i_} -> 0, {i_, j_} -> f[i, j]}, {n1, n1}];

This matrix contains 0 and 1.

From the matrix, I’d like construct a list of items which contains 3 columns, whose first line is written: source, target and type. Below of the "type" will write “Directed”. The elements non-zero of the matriz are connect by lines and column. In this elements non-zero, the number of the line is "source" and the number of the column is "target", as in a graph. The file will be export in format .csv.

For example: If the adjacency matrix is {0,1,0,1}, {1,0,0,1}, {0,1,0,0}, {1,0,1,0} the file wiil be of the type:

Source;Target;Type

1;2;Directed

1;4;Directed

2;1;Directed

2;4;Directed

3;2;Directed

4;1;Directed

4;3;Directed

Can somebody help me?

$\endgroup$
  • $\begingroup$ To start you off: EdgeList[AdjacencyGraph[{{0, 1, 0, 1}, {1, 0, 0, 1}, {0, 1, 0, 0}, {1, 0, 1, 0}}]]. $\endgroup$ – J. M. will be back soon Apr 21 '17 at 2:05
  • 1
    $\begingroup$ Why don't you just export to a graph format that Gephi supports, like GML? $\endgroup$ – Szabolcs Apr 21 '17 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.