# Is there a lazy way to create another variable based on the dimensionality of one variable?

**URL:** https://discourse.julialang.org/t/is-there-a-lazy-way-to-create-another-variable-based-on-the-dimensionality-of-one-variable/72153
**Category:** Optimization (Mathematical)
**Tags:** question, jump
**Created:** [November 27, 2021, 7:59am UTC](https://discourse.julialang.org/t/is-there-a-lazy-way-to-create-another-variable-based-on-the-dimensionality-of-one-variable/72153 "2021-11-27T07:59:15Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![iiitr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iiitr/32/24586_2.png) [@iiitr](https://discourse.julialang.org/u/iiitr)
#### Post date: [November 27, 2021, 7:59am UTC](https://discourse.julialang.org/t/is-there-a-lazy-way-to-create-another-variable-based-on-the-dimensionality-of-one-variable/72153/1 "2021-11-27T07:59:15Z")

</div>

Hi all,

There are times when I need to create another variable based on the shape of one variable. Since, I don’t know the dimension of the variable. Therefore, I usually write a lot of `if-elseif-else-end` blocks to determine the dimension of the variable and then create a new variable based on its dimension.

I’m asking if there can all be a lazy way to achieve this, as follows:

```julia
x = @variable(model, [1:2, 1:3])
y = @variable(model, shape_like(x))

```

Thanks a lot!

---

<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 27, 2021, 8:12am UTC](https://discourse.julialang.org/t/is-there-a-lazy-way-to-create-another-variable-based-on-the-dimensionality-of-one-variable/72153/2 "2021-11-27T08:12:07Z")

</div>

There is no specific support for this. But you may be interested in

[https://github.com/jump-dev/JuMP.jl/pull/2812](https://github.com/jump-dev/JuMP.jl/pull/2812)
