ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 15 Dec 2015 11:02:25 -0600How to make a graph from an latin square matrix ?http://ask.sagemath.org/question/31564/how-to-make-a-graph-from-an-latin-square-matrix/As the question says I want to write a program that will make a graph from the given matrix ?
How can I do that in Sage?Mon, 14 Dec 2015 13:20:10 -0600http://ask.sagemath.org/question/31564/how-to-make-a-graph-from-an-latin-square-matrix/Answer by kcrisman for <p>As the question says I want to write a program that will make a graph from the given matrix ?</p>
<p>How can I do that in Sage?</p>
http://ask.sagemath.org/question/31564/how-to-make-a-graph-from-an-latin-square-matrix/?answer=31583#post-id-31583I don't exactly know how a Latin square leads to a graph. But here is [the graph documentation](http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/graph.html#supported-formats) regarding *adjacency* matrices.
sage: M = Matrix([(0,1,0,0,1,1,0,0,0,0),(1,0,1,0,0,0,1,0,0,0), \
(0,1,0,1,0,0,0,1,0,0), (0,0,1,0,1,0,0,0,1,0),(1,0,0,1,0,0,0,0,0,1), \
(1,0,0,0,0,0,0,1,1,0), (0,1,0,0,0,0,0,0,1,1),(0,0,1,0,0,1,0,0,0,1), \
(0,0,0,1,0,1,1,0,0,0), (0,0,0,0,1,0,1,1,0,0)])
sage: M
[0 1 0 0 1 1 0 0 0 0]
[1 0 1 0 0 0 1 0 0 0]
[0 1 0 1 0 0 0 1 0 0]
[0 0 1 0 1 0 0 0 1 0]
[1 0 0 1 0 0 0 0 0 1]
[1 0 0 0 0 0 0 1 1 0]
[0 1 0 0 0 0 0 0 1 1]
[0 0 1 0 0 1 0 0 0 1]
[0 0 0 1 0 1 1 0 0 0]
[0 0 0 0 1 0 1 1 0 0]
sage: G = Graph(M); G
Graph on 10 verticesTue, 15 Dec 2015 08:06:25 -0600http://ask.sagemath.org/question/31564/how-to-make-a-graph-from-an-latin-square-matrix/?answer=31583#post-id-31583Comment by kcrisman for <p>I don't exactly know how a Latin square leads to a graph. But here is <a href="http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/graph.html#supported-formats">the graph documentation</a> regarding <em>adjacency</em> matrices.</p>
<pre><code>sage: M = Matrix([(0,1,0,0,1,1,0,0,0,0),(1,0,1,0,0,0,1,0,0,0), \
(0,1,0,1,0,0,0,1,0,0), (0,0,1,0,1,0,0,0,1,0),(1,0,0,1,0,0,0,0,0,1), \
(1,0,0,0,0,0,0,1,1,0), (0,1,0,0,0,0,0,0,1,1),(0,0,1,0,0,1,0,0,0,1), \
(0,0,0,1,0,1,1,0,0,0), (0,0,0,0,1,0,1,1,0,0)])
sage: M
[0 1 0 0 1 1 0 0 0 0]
[1 0 1 0 0 0 1 0 0 0]
[0 1 0 1 0 0 0 1 0 0]
[0 0 1 0 1 0 0 0 1 0]
[1 0 0 1 0 0 0 0 0 1]
[1 0 0 0 0 0 0 1 1 0]
[0 1 0 0 0 0 0 0 1 1]
[0 0 1 0 0 1 0 0 0 1]
[0 0 0 1 0 1 1 0 0 0]
[0 0 0 0 1 0 1 1 0 0]
sage: G = Graph(M); G
Graph on 10 vertices
</code></pre>
http://ask.sagemath.org/question/31564/how-to-make-a-graph-from-an-latin-square-matrix/?comment=31589#post-id-31589Yes, I thought of that, but usually one wouldn't say graph, but rather multigraph or weighted graph. Hopefully the original poster can clarify.Tue, 15 Dec 2015 11:02:25 -0600http://ask.sagemath.org/question/31564/how-to-make-a-graph-from-an-latin-square-matrix/?comment=31589#post-id-31589Comment by slelievre for <p>I don't exactly know how a Latin square leads to a graph. But here is <a href="http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/graph.html#supported-formats">the graph documentation</a> regarding <em>adjacency</em> matrices.</p>
<pre><code>sage: M = Matrix([(0,1,0,0,1,1,0,0,0,0),(1,0,1,0,0,0,1,0,0,0), \
(0,1,0,1,0,0,0,1,0,0), (0,0,1,0,1,0,0,0,1,0),(1,0,0,1,0,0,0,0,0,1), \
(1,0,0,0,0,0,0,1,1,0), (0,1,0,0,0,0,0,0,1,1),(0,0,1,0,0,1,0,0,0,1), \
(0,0,0,1,0,1,1,0,0,0), (0,0,0,0,1,0,1,1,0,0)])
sage: M
[0 1 0 0 1 1 0 0 0 0]
[1 0 1 0 0 0 1 0 0 0]
[0 1 0 1 0 0 0 1 0 0]
[0 0 1 0 1 0 0 0 1 0]
[1 0 0 1 0 0 0 0 0 1]
[1 0 0 0 0 0 0 1 1 0]
[0 1 0 0 0 0 0 0 1 1]
[0 0 1 0 0 1 0 0 0 1]
[0 0 0 1 0 1 1 0 0 0]
[0 0 0 0 1 0 1 1 0 0]
sage: G = Graph(M); G
Graph on 10 vertices
</code></pre>
http://ask.sagemath.org/question/31564/how-to-make-a-graph-from-an-latin-square-matrix/?comment=31588#post-id-31588To a matrix with nonnegative integer entries, one could associate a graph, allowing multiple edges and loops. If the entries were not necessarily integer, one could think of a graph with weighted edges.Tue, 15 Dec 2015 10:15:00 -0600http://ask.sagemath.org/question/31564/how-to-make-a-graph-from-an-latin-square-matrix/?comment=31588#post-id-31588