Thanks for the suggestions. I'm on a Mac using OS 10.6.8. I created the csv file using Excel and saving as a csv file. Here's what happened when I tried rU in place of r: sage: cat "medalcomparison4.csv" 1,0,0,1,0sage: f = open("medalcomparison4.csv",'rU') sage: entries = map(lambda x:x.strip('\n').split(','), f.readlines()) sage: entries [['0', '0', '0', '0', '0'], ['1', '0', '0', '1', '0'], ['1', '1', '0', '1', '1'], ['1', '0', '0', '0', '0'], ['1', '0', '0', '1', '0']] sage: m = Matrix(entries) --------------------------------------------------------------------------- TypeError Traceback (most recent call last)
/Users/matrngnew/<ipython console> in <module>() /Applications/sage-4.7.2/local/lib/python2.6/site-packages/sage/matrix/constructor.pyc in matrix(*args, **kwds) 584 585 if nrows > 0 and ncols > 0 and ring is None: --> 586 entries, ring = prepare(entries) 587 588 elif isinstance(args[0], dict): /Applications/sage-4.7.2/local/lib/python2.6/site-packages/sage/matrix/constructor.pyc in prepare(w) 708 ring = rings.CDF 709 elif not rings.is_Ring(ring): --> 710 raise TypeError, "unable to find a common ring for all elements" 711 return entries, ring 712 TypeError: unable to find a common ring for all elements 2011/12/5 Lukáš Lánský <lu...@lansky.name> > Hi, this is obviously a problem with the system-specific line-ending > characters. What happens if you try to replace > open("medalcomparison4.csv",'r') with open("medalcomparison4.csv","rU") ? > > Have a nice day. > Lukáš Lánský. > > Dne 5.12.2011 16:19, Raymond N. Greenwell napsal(a): > > This is getting warmer, but something must be different about my csv file. > It appears to me to contain the following: > 0 0 0 0 0 1 0 0 1 0 1 1 0 1 1 1 0 0 0 0 1 0 0 1 0 Here's what Sage > does: > sage: cat "medalcomparison4.csv" > 1,0,0,1,0sage: f = open("medalcomparison4.csv",'r') > sage: entries = map(lambda x:x.strip('\n').split(','), f.readlines()) > sage: entries > [['0', '0', '0', '0', '0\r1', '0', '0', '1', '0\r1', '1', '0', '1', > '1\r1', '0', '0', '0', '0\r1', '0', '0', '1', '0']] > sage: entries = map(lambda x:map(Integer,x), entries) > sage: entries > [[0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 11, 0, 0, 0, 1, 0, 0, 1, 0]] > sage: m = Matrix(entries) > sage: m > [ 0 0 0 0 1 0 0 1 1 1 0 1 11 0 0 0 1 0 0 1 0] > sage: D = DiGraph(m) > --------------------------------------------------------------------------- > ValueError Traceback (most recent call last) > > /Users/matrngnew/<ipython console> in <module>() > > > /Applications/sage-4.7.2/local/lib/python2.6/site-packages/sage/graphs/digraph.pyc > in __init__(self, data, pos, loops, format, boundary, weighted, > implementation, sparse, vertex_labels, **kwds) > 552 multiedges = ( len(uniq(positions)) < total ) > 553 except AssertionError: > --> 554 raise ValueError(msg) > 555 num_verts = data.nrows() > 556 elif format == 'DiGraph': > > ValueError: Non-symmetric or non-square matrix assumed to be an > incidence matrix: There must be two nonzero entries (-1 & 1) per column. > > I will try fiddling with the csv file. > > On Sun, Dec 4, 2011 at 2:50 AM, Nathann Cohen <nathann.co...@gmail.com>wrote: > >> > 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. > -- 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.