Alec
Alec

Reputation: 4482

How to get each index of one or more of an array's dimensions?

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

Upvotes: 2

Views: 371

Answers (1)

Sundar R
Sundar R

Reputation: 14735

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)

Upvotes: 4

Related Questions