> I'm still stuck at creating my digraph from my csv file. My csv file is
essentially an adjacency matrix of 0's and 1's. I can import it, but I
can't convert it into an adjacency matrix that can then be created into a
digraph. Any more ideas? Thanks in advance for any help.

What about this ?

sage: cat "dg.csv"
0, 1, 0, 1
1, 1, 0, 1
1, 0, 0, 1
0, 0, 0, 1

sage: f = open("dg.csv",'r')
sage: # Removing '\n' and splitting into cells
sage: entries = map(lambda x:x.strip('\n').split(','), f.readlines())
sage: entries
[['0', ' 1', ' 0', ' 1'], ['1', ' 1', ' 0', ' 1'], ['1', ' 0', ' 0', ' 1'],
['0', ' 0', ' 0', ' 1']]
sage: # Casting from str to integers
sage: entries = map(lambda x:map(Integer,x), entries)
sage: entries
sage: # A matrix
sage: m = Matrix(entries)
sage: m
[0 1 0 1]
[1 1 0 1]
[1 0 0 1]
[0 0 0 1]
sage: # A Digraph
sage: D = DiGraph(m)
sage: D.edges()
[(0, 1, None), (0, 3, None), (1, 0, None), (1, 1, None), (1, 3, None), (2,
0, None), (2, 3, None), (3, 3, None)]

Nathann

-- 
You received this message because you are subscribed to the Google Groups 
"sage-combinat-devel" group.
To post to this group, send email to sage-combinat-devel@googlegroups.com.
To unsubscribe from this group, send email to 
sage-combinat-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sage-combinat-devel?hl=en.

Reply via email to