How to get linear indices of array along a slice k?

Hey,
I need to know all linear indices of an array along a certain dimension k, keeping all other dims fixed at some value. I want to know indices along that slice.

I wanted to do

A = ones(3,4,5)
# what are the linearindices at view(A,2,4,:)?
linearindices(view(A,2,4,:))  # gives me 1:5

so I do

id = reshape(linearindices(A),size(A))
view(id,2,4,:)
5-element SubArray{Int64,1,Base.ReshapedArray{Int64,3,Base.OneTo{Int64},Tuple{}},Tuple{Int64,Int64,Colon},true}:
 11
 23
 35
 47
 59

can I do better?

I guess Iā€™m looking for eachindex(A,2,4,:)

1 Like