# Accessing wanted indices of a vector

**URL:** <https://discourse.julialang.org/t/accessing-wanted-indices-of-a-vector/71048>\
**Category:** New to Julia\
**Tags:** question, indexing, vector\
**Created:** [November 6, 2021, 12:47pm UTC](https://discourse.julialang.org/t/accessing-wanted-indices-of-a-vector/71048 "2021-11-06T12:47:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FH96](https://avatars.discourse-cdn.com/v4/letter/f/4da419/32.png) [@FH96](https://discourse.julialang.org/u/FH96)\
**Post date:** [November 6, 2021, 12:47pm UTC](https://discourse.julialang.org/t/accessing-wanted-indices-of-a-vector/71048/1 "2021-11-06T12:47:05Z")

</div>

I have a vector ( `Vector{VariableRef} `) :  
`@variable(model,v[1:2583)])`

I want to choose some indices by means of `irreversible_indices`  
which I get it’s type as `Vector{Int64}`

but when I try to run this :  
`v[irreversible_indices] `  
this is the error:  
`BoundsError: attempt to access 2583-element Vector{VariableRef} at index [[0, 1, 4, 5, 6, 7, 8, 9, 10, 12 … 2571, 2572, 2574, 2576, 2577, 2578, 2579, 2580, 2581, 2582]]`

or if I try like this :  
`@constraint(model,[j in irreversible_indices],v[j]>=0)`  
error:  
` BoundsError: attempt to access 2583-element Vector{VariableRef} at index [0]`

however if I print elements of `irreversible_indices` the result is like 0, 1, 5, 6 ,… not [0], [1], [5]…

what is wrong here???

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [November 6, 2021, 12:51pm UTC](https://discourse.julialang.org/t/accessing-wanted-indices-of-a-vector/71048/2 "2021-11-06T12:51:01Z")

</div>

The 0 in `irreversible_indices` is probably the problem, because arrays/vecors are 1-based in Julia:

```julia
julia> v=[1,2,3]
3-element Vector{Int64}:
 1
 2
 3

julia> i=[0,2,3]
3-element Vector{Int64}:
 0
 2
 3

julia> v[i]
ERROR: BoundsError: attempt to access 3-element Vector{Int64} at index [[0, 2, 3]]
Stacktrace:
 [1] throw_boundserror(A::Vector{Int64}, I::Tuple{Vector{Int64}})
   @ Base .\abstractarray.jl:651
 [2] checkbounds
   @ .\abstractarray.jl:616 [inlined]
 [3] _getindex
   @ .\multidimensional.jl:831 [inlined]
 [4] getindex(A::Vector{Int64}, I::Vector{Int64})
   @ Base .\abstractarray.jl:1170
 [5] top-level scope
   @ REPL[10]:1

```

---

<div class="post-metadata">

**Author:** ![FH96](https://avatars.discourse-cdn.com/v4/letter/f/4da419/32.png) [@FH96](https://discourse.julialang.org/u/FH96)\
**Post date:** [November 7, 2021, 6:42am UTC](https://discourse.julialang.org/t/accessing-wanted-indices-of-a-vector/71048/3 "2021-11-07T06:42:05Z")

</div>

Thanks a lot!!! 🙏 🙏 🙏  
taking indices from python resulted in a zero index
