# Indexing Array

**URL:** <https://discourse.julialang.org/t/indexing-array/33866>\
**Category:** General Usage\
**Created:** [January 27, 2020, 6:08pm UTC](https://discourse.julialang.org/t/indexing-array/33866 "2020-01-27T18:08:55Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arega\_Getaneh](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@Arega\_Getaneh](https://discourse.julialang.org/u/Arega_Getaneh)\
**Post date:** [January 27, 2020, 6:08pm UTC](https://discourse.julialang.org/t/indexing-array/33866/1 "2020-01-27T18:08:55Z")

</div>

```julia
Use square brackets [] for indexing an Array.

Stacktrace:
 [1] mapreduce_first(::Array{Float64,2}, ::Function, ::Int64) at .\reduce.jl:301
 [2] mapreduce(::Array{Float64,2}, ::Function, ::Int64) at .\reduce.jl:328
 [3] sum(::Array{Float64,2}, ::Int64) at .\reduce.jl:403
 [4] general_equi_NLP(::Int64, ::Int64, ::Int64, ::Array{Float64,2}, ::Array{Float64,2}, ::Array{Float64,2}, ::Array{Float64,2}, ::Array{Float64,1}, ::Int64, ::Array{Float64,1}, ::Float64, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Int64, ::Float64, ::Array{Float64,2}, ::Array{Float64,2}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}) at .\In[2]:38
 [5] top-level scope at In[4]:1
Where is the problem and how to correct it. The code was written using Julia 0.64. Now trying to use Julia 1.12. But it gives me this error message.
```

---

<div class="post-metadata">

**Author:** ![kevinczimmerman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevinczimmerman/32/13040_2.png) [@kevinczimmerman](https://discourse.julialang.org/u/kevinczimmerman)\
**Post date:** [January 27, 2020, 6:16pm UTC](https://discourse.julialang.org/t/indexing-array/33866/2 "2020-01-27T18:16:11Z")

</div>

You’re going to want to post the code that generated the above error so that people can help you.

---

<div class="post-metadata">

**Author:** ![Arega\_Getaneh](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@Arega\_Getaneh](https://discourse.julialang.org/u/Arega_Getaneh)\
**Post date:** [January 27, 2020, 6:25pm UTC](https://discourse.julialang.org/t/indexing-array/33866/3 "2020-01-27T18:25:07Z")

</div>

The code I am working is quite long. It worked in the previous version (0.64). The Problem is with 1.12 version. The question is what is changed in the new one regarding indexing?

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 27, 2020, 6:26pm UTC](https://discourse.julialang.org/t/indexing-array/33866/4 "2020-01-27T18:26:25Z")

</div>

Impossible to say without code. You could try running your code on 0.7 to get deprecation warnings, which were pretty complete and specific.

---

<div class="post-metadata">

**Author:** ![Arega\_Getaneh](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@Arega\_Getaneh](https://discourse.julialang.org/u/Arega_Getaneh)\
**Post date:** [January 27, 2020, 6:27pm UTC](https://discourse.julialang.org/t/indexing-array/33866/5 "2020-01-27T18:27:43Z")

</div>

That means I have to install it and all the packages I need? That means too tedious!

---

<div class="post-metadata">

**Author:** ![kevinczimmerman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevinczimmerman/32/13040_2.png) [@kevinczimmerman](https://discourse.julialang.org/u/kevinczimmerman)\
**Post date:** [January 27, 2020, 6:33pm UTC](https://discourse.julialang.org/t/indexing-array/33866/6 "2020-01-27T18:33:51Z")

</div>

The alternative is the community takes continuous guesses at solutions with almost no context. We are eager to help but there is not much else we can do without additional information. If you can isolate the portion that isn’t working and provide a minimal working example, it would go a long way.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [January 27, 2020, 6:37pm UTC](https://discourse.julialang.org/t/indexing-array/33866/7 "2020-01-27T18:37:31Z")

</div>

You are apparently trying to index into an array, and not using square brackets. That’s pretty much what I can tell from this. So, maybe try to use brackets?

---

<div class="post-metadata">

**Author:** ![Arega\_Getaneh](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@Arega\_Getaneh](https://discourse.julialang.org/u/Arega_Getaneh)\
**Post date:** [January 27, 2020, 6:41pm UTC](https://discourse.julialang.org/t/indexing-array/33866/8 "2020-01-27T18:41:43Z")

</div>

```nohighlight
    
    m = JuMP.direct_model(Gurobi.Optimizer(OutputFlag=0))
Vgamma_S=gamma_S-beta_S.*sum(Q,1)'#new deefinition
    tau_i=1. /(beta_S*(1+delta_i)'.+c')'
   Varphi_w=1. /(1+beta_S.*sum(tau_i,1)')
   var_PF_i=-beta_F*(1+varphi_i*(I+J-1))
   var_PF_j=-beta_F*(1+varphi_j*(I+J-1))
  var_PS_i= beta_S'.^2. *Varphi_w'.*(-(1+delta_i).*tau_i-varphi_i.*(sum(((1+delta_i).*tau_i),1).-(1+delta_i).*tau_i))
   var_PS_j=0*ones(J,W)
   var_qS_i=tau_i.*beta_S'.*(1+delta_i)+tau_i.*var_PS_i
   var_qS_j=-1*ones(J,W) `
Here is part of the code. Hope this tells you where the problem lies.
```

---

<div class="post-metadata">

**Author:** ![Arega\_Getaneh](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@Arega\_Getaneh](https://discourse.julialang.org/u/Arega_Getaneh)\
**Post date:** [January 27, 2020, 6:44pm UTC](https://discourse.julialang.org/t/indexing-array/33866/9 "2020-01-27T18:44:41Z")

</div>

In the above code, i and j are indices. It seems the new version requires to do this like tau[i] instead of tau\_i?

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 27, 2020, 11:24pm UTC](https://discourse.julialang.org/t/indexing-array/33866/10 "2020-01-27T23:24:35Z")

</div>

Seems like a good guess. Give it a try and see what happens.

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [January 28, 2020, 1:09am UTC](https://discourse.julialang.org/t/indexing-array/33866/11 "2020-01-28T01:09:05Z")

</div>

I think one problem is things like `sum(tau_i, 1)`. That should be `sum(tau_i; dims = 1)`. The error isn’t the most helpful here; what’s happening is that with the newer version of sum, the first argument is treated as a function to apply to each element before summing, but since `tau_i` is not a function but an array, it gives you that message. (While these kinds of errors can be frustrating, my understanding is a lot of effort was put into Julia 0.7 to give good deprecation messages to prevent the frustration!)

Edit: you may also run into differences if you are using a different version of JuMP now than you were with Julia 0.64. So it might be a good idea to look at the JuMP repo as well for changes to JuMP over the past few versions, or to make sure you are using the same version of JuMP and do the Julia update first, and then change versions of JuMP and update the JuMP code.
