# Can JuMP.jl create a sparse array variable that can be used as a full matrix?

**URL:** <https://discourse.julialang.org/t/can-jump-jl-create-a-sparse-array-variable-that-can-be-used-as-a-full-matrix/69114>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [October 2, 2021, 2:15pm UTC](https://discourse.julialang.org/t/can-jump-jl-create-a-sparse-array-variable-that-can-be-used-as-a-full-matrix/69114 "2021-10-02T14:15:31Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [October 3, 2021, 1:21am UTC](https://discourse.julialang.org/t/can-jump-jl-create-a-sparse-array-variable-that-can-be-used-as-a-full-matrix/69114/4 "2021-10-03T01:21:15Z")

</div>

Thank you very much for your reply! The code you provided is very helpful.

On the basis of the solution you provided, I raised a new question. If you have time, I’d like to ask you for help!

> [@How to extend the JuMP @variable so that it can construct a sparse array which can be used as a full matrix?](https://discourse.julialang.org/t/how-to-extend-the-jump-variable-so-that-it-can-construct-a-sparse-array-which-can-be-used-as-a-full-matrix/69125):
>
> Hi all In fact, this question is a derivative of my last question. [https://discourse.julialang.org/t/can-jump-jl-create-a-sparse-array-variable-that-can-be-used-as-a-full-matrix/69114/2?u=iiitr](https://discourse.julialang.org/t/can-jump-jl-create-a-sparse-array-variable-that-can-be-used-as-a-full-matrix/69114/2) I want to create a 4x4 array variables, but it only has a value at the index (1, 2), (2, 1), (2, 3), (3, 2) and the rest is 0. @blegat provide several solutions, one of which best meets my expectations, as follows: model = Model() x = zeros(AffExpr, 3, 3) x[1, 1] = @variable(model, base\_name = "x[1, …

---

_[View the full topic](https://discourse.julialang.org/t/can-jump-jl-create-a-sparse-array-variable-that-can-be-used-as-a-full-matrix/69114)._
