# How to define an array of variables in JuMP that has different lengths in different dimensions

**URL:** https://discourse.julialang.org/t/how-to-define-an-array-of-variables-in-jump-that-has-different-lengths-in-different-dimensions/89598
**Category:** Optimization (Mathematical)
**Tags:** jump
**Created:** [November 1, 2022, 4:48am UTC](https://discourse.julialang.org/t/how-to-define-an-array-of-variables-in-jump-that-has-different-lengths-in-different-dimensions/89598 "2022-11-01T04:48:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Alex\_ricci](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@Alex\_ricci](https://discourse.julialang.org/u/Alex_ricci)
#### Post date: [November 1, 2022, 4:48am UTC](https://discourse.julialang.org/t/how-to-define-an-array-of-variables-in-jump-that-has-different-lengths-in-different-dimensions/89598/1 "2022-11-01T04:48:25Z")

</div>

I have a parameter called z\_{t, w} with the size of 2 \times 2 which is a vector of vectors.  
For example, z\_{1,1} and z\_{2,1} are

```julia
z[1,1] = [10 10 30 40 50] 
z[2,1] = [20 30 40] 

```

I want to define a variable y based on z. The first two indices of y and z are the same. However, y has one extra index which is defined based on the length corresponding z element.  
since the `length(z[1,1]) = 5` and `length(z[2,1]) = 3`,  
Therefore, we should have

```julia
y[1,1,:] = 
y[1,1,1] 
y[1,1,2] 
y[1,1,3] 
y[1,1,4] 
y[1,1,5] 

```

and

```julia
y[2,1,:] = 
y[2,1,1] 
y[2,1,2] 
y[2,1,3] 

```

Is it possible to define such a variable in Julia using the JuMP package?

---

<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: [November 1, 2022, 6:43am UTC](https://discourse.julialang.org/t/how-to-define-an-array-of-variables-in-jump-that-has-different-lengths-in-different-dimensions/89598/2 "2022-11-01T06:43:44Z")

</div>

```julia
@variable(model, y[i=1:2, j=1:2, k=1:length(z[i, j])])

```

Documentation: [Variables · JuMP](https://jump.dev/JuMP.jl/stable/manual/variables/#variable_sparseaxisarrays)
