# Index rows of arbitrary dimensional array?

**URL:** <https://discourse.julialang.org/t/index-rows-of-arbitrary-dimensional-array/58312>\
**Category:** General Usage\
**Created:** [March 31, 2021, 4:27pm UTC](https://discourse.julialang.org/t/index-rows-of-arbitrary-dimensional-array/58312 "2021-03-31T16:27:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Satvik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/satvik/32/20486_2.png) [@Satvik](https://discourse.julialang.org/u/Satvik)\
**Post date:** [March 31, 2021, 4:27pm UTC](https://discourse.julialang.org/t/index-rows-of-arbitrary-dimensional-array/58312/1 "2021-03-31T16:27:31Z")

</div>

I have some code that receives vectors or matrices, and I would like to get certain rows while preserving the dimensionality of the input. E.g.

```julia
arr = [1, 2, 3]
mat = [1 2; 3 4; 5 6]

get_rows(arr, 2, 3) == [2, 3]
get_rows(mat, 2, 3) == [3 4; 5 6]

```

I haven’t been able to figure out how to do this with indexing – for example, `arr[2:3, :]` gets the right data but converts it to a matrix, and I wasn’t able to find anything in the documentation. Is there a way to slice over a single dimension while leaving the others intact?

---

<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:** [March 31, 2021, 4:39pm UTC](https://discourse.julialang.org/t/index-rows-of-arbitrary-dimensional-array/58312/2 "2021-03-31T16:39:14Z")

</div>

```julia
julia> collect(selectdim(arr,1,2:3))
2-element Vector{Int64}:
 2
 3

julia> collect(selectdim(mat,1,2:3))
2×2 Matrix{Int64}:
 3 4
 5 6

```
