Hello,

I have the current function in Julia but I realize it is quite repetitive and bad. Is there any way of generalizing this function? I want to create a function that takes in an array and range and returns the array indexed from the last dimension.

```
function lastdimrange(arr::Array{T,N}, r::R) where {T,N,R}
if N == 1
return arr[r]
elseif N > 1
new_dims = tuple((size(arr, i) for i in 1:N-1)..., length(r))
result = similar(arr[:, :, 1], new_dims)
if N == 2
result .= arr[:, r]
elseif N == 3
result .= arr[:, :, r]
elseif N == 4
result .= arr[:, :, :, r]
elseif N == 5
result .= arr[:, :, :, :, r]
elseif N == 6
result .= arr[:, :, :, :, :, r]
elseif N == 7
result .= arr[:, :, :, :, :, :, r]
else
error("This function does not support arrays with more than 7 dimensions.")
end
return result
else
error("Invalid array dimensions.")
end
end
```