Address the error "BoundsError: attempt to access 0-element Vector{Float64} at index [1]"


I am using the “IntervalArithmetic.jl” package in Pluto.jl notebook. While executing the code code I am getting the following error

BoundsError: attempt to access 0-element Vector{Float64} at index [1]
getindex(::Vector{Float64}, ::Int64)@array.jl:924

The piece of code from where the error is coming -

XYnew = [(0..5), (0..5), (0..5), (0..5)]
mid_X = mid.(XYnew)
		arg = mid_X[1]

Could you please let me know the possible reason for the error? Not only this time but I face this type of error many times. So, the solution could be really helpful for me.
Thank you

From your code the error is not reproducible for me.

julia> using IntervalArithmetic

julia> XYnew = [(0..5), (0..5), (0..5), (0..5)]
4-element Vector{Interval{Float64}}:
 [0, 5]
 [0, 5]
 [0, 5]
 [0, 5]

julia> mid_X = mid.(XYnew)
4-element Vector{Float64}:

julia> mid_X[1]

You mentioned that you are using Pluto.jl, so my guess is that there is probably another cell in your notebook modifying any of the variables resulting in the error.

1 Like

Dear @p-gw, there is no other cell but one thing I would like to mention is that I am using this code inside a “for” loop.

for i in 1:n
		mid_X = map(mid, XYnew)
		#mid_X = mid.(XYnew)
		arg1 = mid_X[1]
		arg2= mid_X[3]
		M = inv(jacobian(arg1, arg2))

You need to show us enough code so we can reproduce the error. What the message is saying is that you try to index into an empty vector, so it would appear that XYnew becomes empty at some point in your loop.

1 Like