📜  在 Julia 中获取有效索引的元组或范围 – axes() 方法

📅  最后修改于: 2021-11-25 04:47:43             🧑  作者: Mango

axes()是 julia 中的一个内置函数,用于返回指定数组的元组或有效索引的有效范围。

示例 1:

# Julia program to illustrate 
# the use of Array axes() method
  
# Getting tuple for 1D array of size 5
# with each element filled with value 4
println(axes(fill(4, (5))))
  
# Getting tuple for 2D array of size 2X3  
# with each element filled with value 5  
println(axes(fill(5, (2, 3))))
  
# Getting tuple for 3D array of size 2X3X4
# with each element filled with value 4
println(axes(fill(4, (2, 3, 4))))

输出:
示例 2:

# Julia program to illustrate 
# the use of Array axes() method
  
# Getting tuple for 1D array of size 5
# with each element filled with value 4
# along with dimension of 1
A = fill(4, (5));
println(axes(A, 1))
  
# Getting tuple for 2D array of size 2X3  
# with each element filled with value 5  
# along with dimension of 2
B = fill(5, (2, 3));
println(axes(B, 2))
  
# Getting tuple for 3D array of size 2X3X4
# with each element filled with value 4
# along with dimension of 3
C = fill(4, (2, 3, 4));
println(axes(C, 3))

输出: