| 1 | initial version |
You can have Sage perform each step of your computation:
sage: M = matrix([[1,1,1], [0,1,1], [0,0,1]])
sage: R = M - identity_matrix(3)
sage: T = R^2
sage: U = matrix(3, 3, [1 if a != 0 else 0 for a in T.list()])
sage: [1 if a != 0 else 0 for a in T.list()] # list of elements, converting any nonzero entry to 1
[0, 0, 1, 0, 0, 0, 0, 0, 0]
sage: U = matrix(3, 3, [1 if a != 0 else 0 for a in T.list()]) # form a matrix out of those entries
sage: G = DiGraph(U) # now get a directed graph
| 2 | No.2 Revision |
You can have Sage perform each step of your computation:
sage: M = matrix([[1,1,1], [0,1,1], [0,0,1]])
sage: R = M - identity_matrix(3)
sage: T = R^2
sage: U = matrix(3, 3, [1 if a != 0 else 0 for a in T.list()])
sage: [1 if a != 0 else 0 for a in T.list()] # list of elements, converting any nonzero entry to 1
[0, 0, 1, 0, 0, 0, 0, 0, 0]
sage: U = matrix(3, 3, [1 if a != 0 else 0 for a in T.list()]) # form a matrix out of those entries
sage: G = DiGraph(U) # now get a directed graph
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.