# How to fix? ArgumentError: row indices I\[k\] must satisfy 1 \<= I\[k\] \<= m

**URL:** <https://discourse.julialang.org/t/how-to-fix-argumenterror-row-indices-i-k-must-satisfy-1-i-k-m/88931>\
**Category:** Graphs\
**Tags:** question, package, graphs\
**Created:** [October 18, 2022, 8:11pm UTC](https://discourse.julialang.org/t/how-to-fix-argumenterror-row-indices-i-k-must-satisfy-1-i-k-m/88931 "2022-10-18T20:11:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![F\_A](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/f_a/32/53159_2.png) [@F\_A](https://discourse.julialang.org/u/F_A)\
**Post date:** [October 18, 2022, 8:11pm UTC](https://discourse.julialang.org/t/how-to-fix-argumenterror-row-indices-i-k-must-satisfy-1-i-k-m/88931/1 "2022-10-18T20:11:41Z")

</div>

Hi,

I’ve already ask this [here](https://github.com/JuliaGraphs/SimpleWeightedGraphs.jl/issues/30). But, perhaps asking here is better.

When I try to build a graph from the following arrays of sources, destinations, and weights, the last line returns an error `ERROR: ArgumentError: column indices J[k] must satisfy 1 = J[k] = n`.  
However, running the documentation example works just fine. Does anyone could see any issues with these three arrays?

```julia
using SimpleWeightedGraphs
using Graphs

s = [0,1,1,2,2,30,30,3,3,3,13,12,12,11,11,10]
e = [1,2,30,3,30,12,10,4,5,13,12,11,14,10,22,9]
w = [30,4.61,4.41,4.6,3.5,4.44,9.91,5.83,4,4,3,4,2,3.5,2,6.6]

g = SimpleWeightedDiGraph(s, e, w)

# returns
# ERROR: ArgumentError: column indices J[k] must satisfy 1 <= J[k] <= n

```

However, the following from [GitHub page](https://github.com/JuliaGraphs/SimpleWeightedGraphs.jl) runs:

```julia
sources = [1,2,1]
destinations = [2,3,3]
weights = [0.5, 0.8, 2.0]
g = SimpleWeightedGraph(sources, destinations, weights)

# returns
{3, 3} undirected simple Int64 graph with Float64 weights

```

Thanks.

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [October 18, 2022, 8:17pm UTC](https://discourse.julialang.org/t/how-to-fix-argumenterror-row-indices-i-k-must-satisfy-1-i-k-m/88931/2 "2022-10-18T20:17:13Z")

</div>

Julia uses 1-based indexing by default. So try initializing with `s = [...] .+ 1` and `e = [...] .+ 1`

---

<div class="post-metadata">

**Author:** ![F\_A](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/f_a/32/53159_2.png) [@F\_A](https://discourse.julialang.org/u/F_A)\
**Post date:** [October 18, 2022, 8:18pm UTC](https://discourse.julialang.org/t/how-to-fix-argumenterror-row-indices-i-k-must-satisfy-1-i-k-m/88931/3 "2022-10-18T20:18:57Z")

</div>

Thanks a lot @Dan
