Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading