# help converting JuMPArray to regular array

**URL:** <https://discourse.julialang.org/t/help-converting-jumparray-to-regular-array/21924>\
**Category:** Optimization (Mathematical)\
**Created:** [March 15, 2019, 7:17pm UTC](https://discourse.julialang.org/t/help-converting-jumparray-to-regular-array/21924 "2019-03-15T19:17:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![levip](https://avatars.discourse-cdn.com/v4/letter/l/6de8d8/32.png) [@levip](https://discourse.julialang.org/u/levip)\
**Post date:** [March 15, 2019, 7:17pm UTC](https://discourse.julialang.org/t/help-converting-jumparray-to-regular-array/21924/1 "2019-03-15T19:17:17Z")

</div>

I’m trying to inspect the dual values of one of my constraints, but I cannot figure out how to convert the returned variable to a regular Array (so that I can ultimately save it to a CSV). I get a 3-dimensional JuMPArray when I call getdual for this constraint (but not for other constraints which have the same dimensions - a question for another time would be why this is happening?).

After solving, this is what I’ve tried -

```julia
> xx = getdual(ramplim)
> typeof(xx)
JuMP.JuMPArray{Float64,3,Tuple{UnitRange{Int64},Array{Int64,1},UnitRange{Int64}}}
> JuMP.size(xx)
(324, 9, 25)

```

I can extract a 1D array but not a 3D array. (I could work with 1D if I understood how it was flattened out, and reconstruct the 3D array… but I’d only do this as a last resort since I’d probably mess it up.)

```julia
> xxarray = xx[:]
72900-element Array{Float64,1}:
 0.0
 0.0
...
> xxarray = xx[:,:,:]
ERROR: Failed attempt to index JuMPArray along dimension 2: Colon() ∉ [2, 3, 4, 5, 6, 7, 8, 9, 10]
Stacktrace:
 [1] macro expansion at /home/users/pjlevi/.julia/v0.6/JuMP/src/JuMPArray.jl:100 [inlined]
 [2] getindex(::JuMP.JuMPArray{Float64,3,Tuple{UnitRange{Int64},Array{Int64,1},UnitRange{Int64}}}, ::Colon, ::Colon, ::Colon) at /home/users/pjlevi/.julia/v0.6/JuMP/src/JuMPArray.jl:40

```

I can’t just convert it either:

```julia
xx = convert(Array,rampl_shadow)
ERROR: MethodError: Cannot `convert` an object of type JuMP.JuMPArray{Float64,3,Tuple{UnitRange{Int64},Array{Int64,1},UnitRange{Int6
4}}} to an object of type Array
This may have arisen from a call to the constructor Array(...),
since type constructors fall back to convert methods.

```

In case it’s helpful: this is how the constraint in question is created

```julia
    @constraint(m,ramplim[g=GENERATORS,t=t_notfirst, o = SCENARIOS],
        p[g,t,o] - p[g,t-1,o] <= (rampmax[g] * pmax[g]))

```

Any guidance would be very appreciated! The ultimate goal here is to save the output as a CSV, but it would be nice to have it as an Array first so that in the future I can manipulate it first.

---

<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:** [March 16, 2019, 7:25pm UTC](https://discourse.julialang.org/t/help-converting-jumparray-to-regular-array/21924/2 "2019-03-16T19:25:24Z")

</div>

Hi @levip,

Welcome to JuMP!

This isn’t really supported, since if you convert it you will lose the indices. As a work around, you can either access the underlying data (`xx.data` Note: this is an internal feature, so it may break at any point!).

A better approach is to just use the JuMPArray as much as possible. If you want to write it to CSV, you can always build an array manually.

```julia
I, J, K = axes(xx)
[xx[i,j,k] for i in I, j in J, k in K]

```

Good luck using JuMP!

p.s. in the future, it’s easier to help if you follow

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![ilias](https://avatars.discourse-cdn.com/v4/letter/i/3bc359/32.png) [@ilias](https://discourse.julialang.org/u/ilias)\
**Post date:** [March 19, 2019, 2:56pm UTC](https://discourse.julialang.org/t/help-converting-jumparray-to-regular-array/21924/3 "2019-03-19T14:56:23Z")

</div>

Try  
`xx = getdual(ramplim)[:,:,:]`
