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

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:

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

Thanks a lot!

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

https://github.com/jump-dev/JuMP.jl/pull/2812

1 Like