Range indexing with multidimensional arrays?

i’m computing indices into an array such that i would have two vectors, e.g. i1, i2

i1 = [2,3,5]
i2 = [5,7,9]

and i will use them to index into a 3 dimensional array to set a value throughout the range dictated by i1 & i2. I could simply do the following

a[i1[1]:i2[1], i1[2]:i2[2], i1[3]:i2[3]] .= x

I’m wondering if there is a more clever way to do it.

I’m not sure if this counts as clever:

a[UnitRange.(i1,i2)...] .= x

I should mention that the broadcasted UnitRange construction comes with a small overhead.

1 Like

well now I know that UnitRange exists which i didn’t know before :slight_smile:
I think this qualifies as clever.
Thanks!