# How to measure a length of an edge?

**URL:** <https://discourse.julialang.org/t/how-to-measure-a-length-of-an-edge/86833>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 6, 2022, 9:20am UTC](https://discourse.julialang.org/t/how-to-measure-a-length-of-an-edge/86833 "2022-09-06T09:20:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Optimization](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/optimization/32/32462_2.png) [@Optimization](https://discourse.julialang.org/u/Optimization)\
**Post date:** [September 6, 2022, 9:20am UTC](https://discourse.julialang.org/t/how-to-measure-a-length-of-an-edge/86833/1 "2022-09-06T09:20:35Z")

</div>

When calling `edges(g)` in Graph.jl , it gives a list. Is there any function that returns the length of and edge in a weighted graph? I know it might seems strange to ask this as we already know the weight (length) of each edge when creating the graph. However, I’d like to know if it;s possible to query in code (not looking the data again)

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [September 6, 2022, 9:30am UTC](https://discourse.julialang.org/t/how-to-measure-a-length-of-an-edge/86833/2 "2022-09-06T09:30:32Z")

</div>

A `weights` function should be available for weighted graphs.

[https://juliagraphs.org/Graphs.jl/dev/core\_functions/core/#Graphs.weights-Tuple{AbstractGraph}](https://juliagraphs.org/Graphs.jl/dev/core_functions/core/#Graphs.weights-Tuple%7BAbstractGraph%7D)

To figure out things like this yourself in the future, remember that it’s possible to search in the documentation, and it’s also possible to search in the Julia REPL help.

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [September 6, 2022, 11:34am UTC](https://discourse.julialang.org/t/how-to-measure-a-length-of-an-edge/86833/3 "2022-09-06T11:34:05Z")

</div>

Knowing the weight of a single edge is not necessarily straightforward depending on the type of graph that you use. The built-in function `weights(g)` returns a (usually sparse) adjacency matrix with _all edge weights_, so in some situations it would be very wasteful. What are you trying to do exactly?

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [September 7, 2022, 6:16am UTC](https://discourse.julialang.org/t/how-to-measure-a-length-of-an-edge/86833/5 "2022-09-07T06:16:43Z")

</div>

Hi again,  
So there is active discussion on the Graphs.jl repo about these labelling problems, which we hope to address in version 2.0. Feel free to pitch in, for instance using [this issue](https://github.com/JuliaGraphs/Graphs.jl/issues/146).  
About your specific question, note that the built-in [`induced_subgraph`](https://juliagraphs.org/Graphs.jl/dev/core_functions/operators/#Graphs.induced_subgraph-Union%7BTuple%7BT%7D,%20Tuple%7BU%7D,%20Tuple%7BT,%20AbstractVector%7BU%7D%7D%7D%20where%20%7BU%3C:Integer,%20T%3C:AbstractGraph%7D) function also returns a translation vector between old and new vertices. Is this the one you are using?
