# Get suffix from Vector of Vectors

**URL:** <https://discourse.julialang.org/t/get-suffix-from-vector-of-vectors/57489>\
**Category:** New to Julia\
**Created:** [March 18, 2021, 5:30pm UTC](https://discourse.julialang.org/t/get-suffix-from-vector-of-vectors/57489 "2021-03-18T17:30:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sleepy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sleepy/32/20296_2.png) [@Sleepy](https://discourse.julialang.org/u/Sleepy)\
**Post date:** [March 18, 2021, 5:30pm UTC](https://discourse.julialang.org/t/get-suffix-from-vector-of-vectors/57489/1 "2021-03-18T17:30:30Z")

</div>

Given is a vector of vectors

s = [[3, 2, 1, 1, 1],[3, 1, 2, 1, 3]]

where all vectors have the same length and an index vector  
i = [3,4]

Is there an easy way to get the subvectors of s, starting at index i.e. 3 to end for the first vector and 4 to end for the second, and so on?

In the example above, the result should be  
s\_suff = [[1,1,1], [1,3]]

I tried  
s\_suff = [s[i][p:end] for i in 1:length(s)]

Thanks

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [March 18, 2021, 5:38pm UTC](https://discourse.julialang.org/t/get-suffix-from-vector-of-vectors/57489/2 "2021-03-18T17:38:56Z")

</div>

> [@Sleepy](#):
>
> s = [[3, 2, 1, 1, 1],[3, 1, 2, 1, 3]]

I think you were almost there (you needed `p[i]`)

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

julia> p = [3,4]
2-element Array{Int64,1}:
 3
 4

julia> [s[i][p[i]:end] for i in 1:length(s) ]
2-element Array{Array{Int64,1},1}:
 [1, 1, 1]
 [1, 3]

```

ps: use backticks to mark the code, makes reading much easier.

---

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [March 19, 2021, 8:36pm UTC](https://discourse.julialang.org/t/get-suffix-from-vector-of-vectors/57489/3 "2021-03-19T20:36:12Z")

</div>

Perhaps a slightly shorter/more readable version would be:

```julia
julia> s = [[3, 2, 1, 1, 1],[3, 1, 2, 1, 3]];

julia> p = [3,4];

julia> [S[P:end] for (S,P) in zip(s,p) ]
2-element Array{Array{Int64,1},1}:
 [1, 1, 1]
 [1, 3]

```
