Indexing Array

Use square brackets [] for indexing an Array.

 [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.

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

1 Like

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?

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

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

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.


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?

    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_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_qS_j=-1*ones(J,W) `
Here is part of the  code. Hope this tells you where the problem lies.

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?

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

1 Like

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.