# Specify a generic array range

**URL:** <https://discourse.julialang.org/t/specify-a-generic-array-range/23489>\
**Category:** General Usage\
**Created:** [April 24, 2019, 10:04pm UTC](https://discourse.julialang.org/t/specify-a-generic-array-range/23489 "2019-04-24T22:04:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ferran\_Mazzanti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ferran_mazzanti/32/7458_2.png) [@Ferran\_Mazzanti](https://discourse.julialang.org/u/Ferran_Mazzanti)\
**Post date:** [April 24, 2019, 10:04pm UTC](https://discourse.julialang.org/t/specify-a-generic-array-range/23489/1 "2019-04-24T22:04:26Z")

</div>

Hi,

I’m building a function where as input I feed an array whose dimensions are not known a priori, but that is going to be of length 100 in each dimension. So it can be, as an input

```julia
a=rand(100) or a=rand(100,100) or a=rand(100,100,100) or ...

```

and I need to filter the middle elements only, so

```julia
a[45:55] or a[45:55,45:55] or a[45:55,45:55,45:55] or ...

```

I thought I could build up a range and use it depending on the number of dimensions of the array. In the simple case a=rand(100), this works

```julia
rng=45:55 
a[rng]

```

but I don’t seem to be able to generalize that to more dimensions. For instance, with a=rand(100,100), what would be the way to get a[45:55,45:55]?  
I’ve tried things like

```julia
rng=45:55 
c=(rng,rng)
a[c]

```

but that does not work

```julia
ERROR: ArgumentError: invalid index: (45:55, 45:55) of type Tuple{UnitRange{Int64},UnitRange{Int64}}
Stacktrace:
 [1] to_index(::Tuple{UnitRange{Int64},UnitRange{Int64}}) at ./indices.jl:270
 [2] to_index(::Array{Float64,2}, ::Tuple{UnitRange{Int64},UnitRange{Int64}}) at ./indices.jl:247
 [3] to_indices at ./indices.jl:298 [inlined]
 [4] to_indices at ./indices.jl:295 [inlined]
 [5] getindex(::Array{Float64,2}, ::Tuple{UnitRange{Int64},UnitRange{Int64}}) at ./abstractarray.jl:927
 [6] top-level scope at none:0

```

What would be the easiest way to specify this multidimensional range?

Thanks in advance,

Ferran.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [April 24, 2019, 10:49pm UTC](https://discourse.julialang.org/t/specify-a-generic-array-range/23489/2 "2019-04-24T22:49:24Z")

</div>

You can just splat your `c` into the indexing expression:

```julia
julia> a[c...]
11×11 Array{Float64,2}:
 ...

```
