# DenseAxisArray not working as expected with single dimensional

**URL:** <https://discourse.julialang.org/t/denseaxisarray-not-working-as-expected-with-single-dimensional/91646>\
**Category:** Optimization (Mathematical)\
**Created:** [December 14, 2022, 5:01pm UTC](https://discourse.julialang.org/t/denseaxisarray-not-working-as-expected-with-single-dimensional/91646 "2022-12-14T17:01:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mitch\_Phillipson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mitch_phillipson/32/42883_2.png) [@Mitch\_Phillipson](https://discourse.julialang.org/u/Mitch_Phillipson)\
**Post date:** [December 14, 2022, 5:01pm UTC](https://discourse.julialang.org/t/denseaxisarray-not-working-as-expected-with-single-dimensional/91646/1 "2022-12-14T17:01:52Z")

</div>

I’m trying to set some values on slices of a DenseAxisArray and am getting an error when setting on a single dimensional DenseAxisArray.

The following code works exactly as expected:

```julia
using JuMP.Containers

D = DenseAxisArray(zeros((3,2)),[:a,:b,:c],[:d,:e])
E = DenseAxisArray(ones((3)),[:a,:b,:c])
I = [:a,:b]

D[I,:d] = E[I]

```

The D array is equal to 1 on the indices corresponding to I and :d. Notice D is two dimensional.

However, when D is a single dimension:

```julia
D = DenseAxisArray(zeros((3)),[:a,:b,:c])
E = DenseAxisArray(ones((3)),[:a,:b,:c])
I = [:a,:b]

D[I] = E[I]

```

I get the following error

```julia
MethodError: no method matching Int64(::Symbol)
Closest candidates are:
  (::Type{T})(!Matched::AbstractChar) where T<:Union{Int32, Int64} at char.jl:51
  (::Type{T})(!Matched::AbstractChar) where T<:Union{AbstractChar, Number} at char.jl:50
  (::Type{T})(!Matched::BigInt) where T<:Union{Int128, Int16, Int32, Int64, Int8} at gmp.jl:359

```

Yes, I can use an explicit for loop to set the values, but I don’t want to. I’ll be doing this many times and a for loop is less clear with more clutter.

I don’t know if this is a bug in the implementation of DenseAxisArray or if I am doing something wrong.

Thanks,  
Mitch

---

<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 14, 2022, 6:02pm UTC](https://discourse.julialang.org/t/denseaxisarray-not-working-as-expected-with-single-dimensional/91646/2 "2022-12-14T18:02:51Z")

</div>

Nice catch, and thanks for the reproducible example.

This looks like a bug: [DenseAxisArray with Symbol key does not support setting · Issue #3151 · jump-dev/JuMP.jl · GitHub](https://github.com/jump-dev/JuMP.jl/issues/3151)

---

<div class="post-metadata">

**Author:** ![Mitch\_Phillipson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mitch_phillipson/32/42883_2.png) [@Mitch\_Phillipson](https://discourse.julialang.org/u/Mitch_Phillipson)\
**Post date:** [December 14, 2022, 6:04pm UTC](https://discourse.julialang.org/t/denseaxisarray-not-working-as-expected-with-single-dimensional/91646/3 "2022-12-14T18:04:13Z")

</div>

Thanks for the reply!

I was hoping it was me doing something wrong, but I’ll do a for loop until a fix comes out.

Thanks again
