# Nested index for a collection of JuMP variables?

**URL:** <https://discourse.julialang.org/t/nested-index-for-a-collection-of-jump-variables/33504>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [January 17, 2020, 7:41pm UTC](https://discourse.julialang.org/t/nested-index-for-a-collection-of-jump-variables/33504 "2020-01-17T19:41:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccoffrin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccoffrin/32/400_2.png) [@ccoffrin](https://discourse.julialang.org/u/ccoffrin)\
**Post date:** [January 17, 2020, 7:41pm UTC](https://discourse.julialang.org/t/nested-index-for-a-collection-of-jump-variables/33504/1 "2020-01-17T19:41:30Z")

</div>

I would like to build a two index JuMP variable that can be accessed like `x[i][j]` rather than `x[i,j]` is there a way to acomplish this with the `@variable` macro?

---

<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:** [January 17, 2020, 8:36pm UTC](https://discourse.julialang.org/t/nested-index-for-a-collection-of-jump-variables/33504/2 "2020-01-17T20:36:44Z")

</div>

```nohighlight
x = model[:x] = [@variable(model, [j in SetJ]) for i in SetI]

```

---

<div class="post-metadata">

**Author:** ![ccoffrin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccoffrin/32/400_2.png) [@ccoffrin](https://discourse.julialang.org/u/ccoffrin)\
**Post date:** [January 21, 2020, 4:40pm UTC](https://discourse.julialang.org/t/nested-index-for-a-collection-of-jump-variables/33504/3 "2020-01-21T16:40:09Z")

</div>

Great solution, thanks @odow!
