Ask Your Question

Revision history [back]

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

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