# Sparse variables in JuMP

**URL:** <https://discourse.julialang.org/t/sparse-variables-in-jump/134630>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [December 18, 2025, 1:26pm UTC](https://discourse.julialang.org/t/sparse-variables-in-jump/134630 "2025-12-18T13:26:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc\_Sevaux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marc_sevaux/32/14986_2.png) [@Marc\_Sevaux](https://discourse.julialang.org/u/Marc_Sevaux)\
**Post date:** [December 18, 2025, 1:26pm UTC](https://discourse.julialang.org/t/sparse-variables-in-jump/134630/1 "2025-12-18T13:26:21Z")

</div>

Hi all,

I’m facing a nice large problem and I would like to reduce the model by creating only the needed variables.

Is there anything close to:

```julia-auto
@variable(model, x[u in 1:n, v in 1:n; if c[u,v] > 0.0], Bin)

```

I get the following message:

```julia-auto
@variable(model, x[u in 1:n, v in 1:n; if c[u,v] > 0.0], Bin); 
# ╙ ── unexpected `]`

```

Thanks for your support.  
M.

---

<div class="post-metadata">

**Author:** ![langestefan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/langestefan/32/207923_2.png) [@langestefan](https://discourse.julialang.org/u/langestefan)\
**Post date:** [December 18, 2025, 2:27pm UTC](https://discourse.julialang.org/t/sparse-variables-in-jump/134630/2 "2025-12-18T14:27:33Z")

</div>

Hi, you probably want:

```julia
@variable(model, x[u in 1:n, v in 1:n; c[u,v] > 0.0], Bin)

```

---

<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:** [December 18, 2025, 7:56pm UTC](https://discourse.julialang.org/t/sparse-variables-in-jump/134630/3 "2025-12-18T19:56:19Z")

</div>

Hi Marc, see this part of the documentation:

> **[SparseAxisArrays - Variables · JuMP](https://jump.dev/JuMP.jl/stable/manual/variables/#variable_sparseaxisarrays)**
>
> The term variable in mathematical optimization has many meanings. For example, optimization variables (also called decision variables) are the unknowns $x$ that we are solving for in the problem: | Documentation for JuMP.
