Home > Software design >  How to get each index of one or more of an array's dimensions?
How to get each index of one or more of an array's dimensions?

Time:08-24

If I want eachindex but only of a specific dimension, what's a good way to accomplish this?

E.g. x is a 3x5x7 Array

x = rand(3,5,7)

And I'd like to get the 2nd dimension's indexes of 1:5, ideally in a way that doesn't assume that the indexing starts at 1

CodePudding user response:

The axes function is a generic way to get that.

  axes(A, d)

  Return the valid range of indices for array A along dimension d.
  julia> A = fill(1, (5,6,7));
  
  julia> axes(A, 2)
  Base.OneTo(6)

  • Related