# Simple question lightgraphs and matrix representation

**URL:** <https://discourse.julialang.org/t/simple-question-lightgraphs-and-matrix-representation/54104>\
**Category:** General Usage\
**Created:** [January 28, 2021, 8:29am UTC](https://discourse.julialang.org/t/simple-question-lightgraphs-and-matrix-representation/54104 "2021-01-28T08:29:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexanderChen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alexanderchen/32/22007_2.png) [@AlexanderChen](https://discourse.julialang.org/u/AlexanderChen)\
**Post date:** [January 28, 2021, 8:29am UTC](https://discourse.julialang.org/t/simple-question-lightgraphs-and-matrix-representation/54104/1 "2021-01-28T08:29:52Z")

</div>

hi,

`T8 = star_graph(8)`

how do I use the `LinAl`g module to get the adjacency matrix of this graph?

best,

---

<div class="post-metadata">

**Author:** ![tmthyln](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tmthyln/32/21607_2.png) [@tmthyln](https://discourse.julialang.org/u/tmthyln)\
**Post date:** [January 28, 2021, 2:31pm UTC](https://discourse.julialang.org/t/simple-question-lightgraphs-and-matrix-representation/54104/2 "2021-01-28T14:31:03Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 28, 2021, 2:48pm UTC](https://discourse.julialang.org/t/simple-question-lightgraphs-and-matrix-representation/54104/3 "2021-01-28T14:48:54Z")

</div>

> [@tmthyln](#):
>
> you can convert it by calling `full` .

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

---

<div class="post-metadata">

**Author:** ![AlexanderChen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alexanderchen/32/22007_2.png) [@AlexanderChen](https://discourse.julialang.org/u/AlexanderChen)\
**Post date:** [January 28, 2021, 3:47pm UTC](https://discourse.julialang.org/t/simple-question-lightgraphs-and-matrix-representation/54104/4 "2021-01-28T15:47:18Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [January 28, 2021, 5:12pm UTC](https://discourse.julialang.org/t/simple-question-lightgraphs-and-matrix-representation/54104/5 "2021-01-28T17:12:01Z")

</div>

`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
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

```

---

<div class="post-metadata">

**Author:** ![tmthyln](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tmthyln/32/21607_2.png) [@tmthyln](https://discourse.julialang.org/u/tmthyln)\
**Post date:** [January 29, 2021, 3:16am UTC](https://discourse.julialang.org/t/simple-question-lightgraphs-and-matrix-representation/54104/6 "2021-01-29T03:16:52Z")

</div>

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.
