X[a,1]'*b[a]==sum(x[a,1].*b[a])?

Hi, all
If I input the following codes,

julia> b[a]
3-element Array{Any,1}:
 1
 2
 3
julia> a
3-element Array{Int64,1}:
 2
 3
 4
julia> model=Model();
julia> @variable(model,x[1:10,1:20])
julia> x[a,1]'*b[a]

there will be an error,
ERROR: MethodError: no method matching zero(::Type{Any})
the expression sum(x[a,1].*b[a]) will not occur error comparing with x[a,1]'*b[a].
Is there some reasons for this occurance?
Thanks a lot!

What is b? From your code, it seems to be an untyped vector, which can hold objects of Any (i.e. all) types. There’s no universal multiplicative identity (i.e., one(x)) for everything, so it fails.

2 Likes

Thank you very much for your reply, Sukera. In fact, b is 10-element Array{Any,1}, and I index vector b with the index a,which a is [2,3,4]. Normally, if b is 10-element Array{float,1}, it can run without errors, but it fails when b is 10-element Array{any,1}.