# JuMP: Error while fixing variable defined as DenseAxisArray using map function

**URL:** <https://discourse.julialang.org/t/jump-error-while-fixing-variable-defined-as-denseaxisarray-using-map-function/62461>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump, optimization\
**Created:** [June 6, 2021, 5:18am UTC](https://discourse.julialang.org/t/jump-error-while-fixing-variable-defined-as-denseaxisarray-using-map-function/62461 "2021-06-06T05:18:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![trathi](https://avatars.discourse-cdn.com/v4/letter/t/7c8e57/32.png) [@trathi](https://discourse.julialang.org/u/trathi)\
**Post date:** [June 6, 2021, 5:18am UTC](https://discourse.julialang.org/t/jump-error-while-fixing-variable-defined-as-denseaxisarray-using-map-function/62461/1 "2021-06-06T05:18:13Z")

</div>

I came across this error when trying to fix a variable defined as `DenseAxisArray`. For example:

```julia
using JuMP
m=Model()
@variable(m, x[0:2,1:3] >=0)
map(y->fix(y,0.0; force=true), x[0, :])

```

This gives an error:

```julia
 MethodError: similar(::JuMP.Containers.DenseAxisArray{VariableRef, 1, Tuple{Base.OneTo{Int64}}, Tuple{JuMP.Containers._AxisLookup{Base.OneTo{Int64}}}}, ::Type{Nothing}, ::Tuple{Base.OneTo{Int64}}) is ambiguous.

```

I am pretty sure it is because I start the first dimension’s indexing from 0 (it works perfectly if the variable `x` is defined as `@variable(m, x[1:3,1:3]`). However, to increase readability, I would like to keep the definition as `@variable(m, x[0:2,1:3]`. So, is there an alternative way of fixing the variables `x[0, :]` (similar to using map function) apart from using a `for` loop to do so?

Thanks!

Note: @odow’s broadcasting solution works equally well. The existing bug will be fixed by @blegat’s [PR](https://github.com/jump-dev/JuMP.jl/pull/2621).

---

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [June 6, 2021, 1:27pm UTC](https://discourse.julialang.org/t/jump-error-while-fixing-variable-defined-as-denseaxisarray-using-map-function/62461/2 "2021-06-06T13:27:31Z")

</div>

Thanks for reporting this bug, it should be fixed by [Fix map for DenseAxisArray with OneTo axes by blegat · Pull Request #2621 · jump-dev/JuMP.jl · GitHub](https://github.com/jump-dev/JuMP.jl/pull/2621)

---

<div class="post-metadata">

**Author:** ![trathi](https://avatars.discourse-cdn.com/v4/letter/t/7c8e57/32.png) [@trathi](https://discourse.julialang.org/u/trathi)\
**Post date:** [June 6, 2021, 2:25pm UTC](https://discourse.julialang.org/t/jump-error-while-fixing-variable-defined-as-denseaxisarray-using-map-function/62461/3 "2021-06-06T14:25:17Z")

</div>

Great! Thanks.

---

<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:** [June 6, 2021, 9:44pm UTC](https://discourse.julialang.org/t/jump-error-while-fixing-variable-defined-as-denseaxisarray-using-map-function/62461/4 "2021-06-06T21:44:09Z")

</div>

> [@trathi](#):
>
> So, is there an alternative way of fixing the variables `x[0, :]` (similar to using map function) apart from using a `for` loop to do so?

Use broadcasting:

```Julia
fix.(x[0, :], 0.0; force = true)

```

---

<div class="post-metadata">

**Author:** ![trathi](https://avatars.discourse-cdn.com/v4/letter/t/7c8e57/32.png) [@trathi](https://discourse.julialang.org/u/trathi)\
**Post date:** [June 7, 2021, 1:11am UTC](https://discourse.julialang.org/t/jump-error-while-fixing-variable-defined-as-denseaxisarray-using-map-function/62461/5 "2021-06-07T01:11:55Z")

</div>

Thanks. This works!
