# Help me with indexing

**URL:** <https://discourse.julialang.org/t/help-me-with-indexing/35203>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, indexing, optimization\
**Created:** [February 27, 2020, 12:07am UTC](https://discourse.julialang.org/t/help-me-with-indexing/35203 "2020-02-27T00:07:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![varun\_yaramasu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/varun_yaramasu/32/10336_2.png) [@varun\_yaramasu](https://discourse.julialang.org/u/varun_yaramasu)\
**Post date:** [February 27, 2020, 12:07am UTC](https://discourse.julialang.org/t/help-me-with-indexing/35203/1 "2020-02-27T00:07:44Z")

</div>

For example

```julia
using JuMP,SCS

m=Model(with_optimizer(SCS.Optimizer))

branch=[1 2 0.1
        3 4 0.1 
        4 5 0.2
        4 6 0.3
        5 6 0.1
       ]

G=length(branch[:,1])

@variable(m,P[branch[1:G,1], branch[1:G,2]])

```

If i type in the above code I’m getting the following error, what would be change i need to do or can anyone suggest me a different notation

Thank you

ERROR: LoadError: Repeated index 4.0. Index sets must have unique elements.  
Stacktrace:  
[1] build\_lookup(::Array{Float64,1}) at C:\Users\yaramasv.juliapro\JuliaPro\_v1.3.1-1\packages\JuMP\MsUSY\src\Containers\DenseAxisArray.jl:23  
[2] \_broadcast\_getindex\_evalf at .\broadcast.jl:630 [inlined]  
[3] \_broadcast\_getindex at .\broadcast.jl:603 [inlined]  
[4] #19 at .\broadcast.jl:1023 [inlined]  
[5] ntuple at .\ntuple.jl:42 [inlined]  
[6] copy at .\broadcast.jl:1023 [inlined]  
[7] materialize at .\broadcast.jl:819 [inlined]  
[8] DenseAxisArray at C:\Users\yaramasv.juliapro\JuliaPro\_v1.3.1-1\packages\JuMP\MsUSY\src\Containers\DenseAxisArray.jl:54 [inlined]  
[9] construct\_undef\_array(::Type{VariableRef}, ::Tuple{Array{Float64,1},Array{Float64,1}}) at C:\Users\yaramasv.juliapro\JuliaPro\_v1.3.1-1\packages\JuMP\MsUSY\src\Containers\DenseAxisArray.jl:96  
[10] JuMP.Containers.DenseAxisArray{VariableRef,N,Ax,L} where L\<:Tuple{Vararg{Dict,N}} where Ax where N(::UndefInitializer, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at C:\Users\yaramasv.juliapro\JuliaPro\_v1.3.1-1\packages\JuMP\MsUSY\src\Containers\DenseAxisArray.jl:91  
[11] top-level scope at C:\Users\yaramasv.juliapro\JuliaPro\_v1.3.1-1\packages\JuMP\MsUSY\src\macros.jl:189  
in expression starting at C:\Users\yaramasv\OneDrive - The University of Colorado Denver\Conference paper\Report\julia\powerflow34.jl:138

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 27, 2020, 2:00am UTC](https://discourse.julialang.org/t/help-me-with-indexing/35203/2 "2020-02-27T02:00:43Z")

</div>

`@variable(model, x[1:2, 1:2])` makes a 2-by-2 matrix of variables. It looks like you want

```nohighlight
@variable(model, P[1:size(branch, 1)])
P[3] # Corresponds to (4, 5, 0.2)

```

or

```nohighlight
S = [(branch[r, 1], branch[r, 2]) for r = 1:size(branch, 1)]
@variable(model, P[S])
P[(3, 4)] # Corresponds to (3, 4, 0.1)

```

---

<div class="post-metadata">

**Author:** ![varun\_yaramasu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/varun_yaramasu/32/10336_2.png) [@varun\_yaramasu](https://discourse.julialang.org/u/varun_yaramasu)\
**Post date:** [February 27, 2020, 5:49pm UTC](https://discourse.julialang.org/t/help-me-with-indexing/35203/3 "2020-02-27T17:49:51Z")

</div>

Thanks for your reply. ![](https://global.discourse-cdn.com/julialang/original/2X/8/801e6a67d3c6fc01bce14e3db44c7797ce4366e0.jpeg)[odow](https://discourse.julialang.org/t/help-me-with-indexing/35203/2)

It helped me a lot thank you once again

---

<div class="post-metadata">

**Author:** ![varun\_yaramasu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/varun_yaramasu/32/10336_2.png) [@varun\_yaramasu](https://discourse.julialang.org/u/varun_yaramasu)\
**Post date:** [February 28, 2020, 4:12am UTC](https://discourse.julialang.org/t/help-me-with-indexing/35203/4 "2020-02-28T04:12:15Z")

</div>

There is one more thing I want to ask.

If we want only the first column of the branch, what we have to do ?

I mean , if I write like this this

```julia
S=[(branch[r,1]) for r= 1:size(branch,1)]
@variable(m,v[S])

```

I’m getting the same error.

Like this

```julia
ERROR: LoadError: Repeated index 4.0. Index sets must have unique elements.
Stacktrace:
 [1] build_lookup(::Array{Float64,1}) at C:\Users\yaramasv\.juliapro\JuliaPro_v1.3.1-1\packages\JuMP\MsUSY\src\Containers\DenseAxisArray.jl:23
 [2] _broadcast_getindex_evalf at .\broadcast.jl:630 [inlined]
 [3] _broadcast_getindex at .\broadcast.jl:603 [inlined]
 [4] #19 at .\broadcast.jl:1023 [inlined]
 [5] ntuple at .\ntuple.jl:41 [inlined]
 [6] copy at .\broadcast.jl:1023 [inlined]
 [7] materialize at .\broadcast.jl:819 [inlined]
 [8] DenseAxisArray at C:\Users\yaramasv\.juliapro\JuliaPro_v1.3.1-1\packages\JuMP\MsUSY\src\Containers\DenseAxisArray.jl:54 [inlined]
 [9] construct_undef_array at C:\Users\yaramasv\.juliapro\JuliaPro_v1.3.1-1\packages\JuMP\MsUSY\src\Containers\DenseAxisArray.jl:96 [inlined]
 [10] JuMP.Containers.DenseAxisArray{VariableRef,N,Ax,L} where L<:Tuple{Vararg{Dict,N}} where Ax where N(::UndefInitializer, ::Array{Float64,1}) at C:\Users\yaramasv\.juliapro\JuliaPro_v1.3.1-1\packages\JuMP\MsUSY\src\Containers\DenseAxisArray.jl:91
 [11] top-level scope at C:\Users\yaramasv\.juliapro\JuliaPro_v1.3.1-1\packages\JuMP\MsUSY\src\macros.jl:189
in expression starting at C:\Users\yaramasv\OneDrive - The University of Colorado Denver\Conference paper\Report\julia\powerflow34.jl:149te code here

```

And I don’t want to use `unique` function also because I want all the elements from first column.

Thank you
