Simple question lightgraphs and matrix representation

hi,

T8 = star_graph(8)

how do I use the LinAlg module to get the adjacency matrix of this graph?

best,

You can use LightGraphs.LinAlg.adjacency_matrix(T8) to get a sparse adjacency matrix for the graph. If you really need a dense matrix, you can convert it by calling full.

2 Likes

full disappeared in Julia 1.0; nowadays you use Matrix(A) to get a full matrix from a sparse one.

3 Likes

thanks it works.

I don’t understand why i need to use this type of notation? How do you call them in julia, and why is this better then eg. a function within the LightGraphs package?

LightGraphs.LinAlg.adjacency_matrix()

best,

adjacency_matrix is a function in the LightGraphs package. You normally don’t need to prefix its name with LightGraphs.LinAlg. For example, this works:

julia> using LightGraphs

julia> g = star_graph(4)
{4, 3} undirected simple Int64 graph

julia> adjacency_matrix(g)
4×4 SparseArrays.SparseMatrixCSC{Int64,Int64} with 6 stored entries:
  [2, 1]  =  1
  [3, 1]  =  1
  [4, 1]  =  1
  [1, 2]  =  1
  [1, 3]  =  1
  [1, 4]  =  1
1 Like

Ah yes, I thought Matrix was more familiar. Wasn’t at a computer though so I just went with the first google result. Next time gotta google twice, answer once.