在 Julia 中获取索引元组 – to_indices() 方法
to_indices()
是 julia 中的一个内置函数,用于将给定的元组 I 转换为索引元组,以用于对数组 A 的索引。
Syntax: to_indices(A, I::Tuple)
Parameters:
- A: Specified array
- I: Specified tuple
Returns: It returns the converted tuple of indices.
示例 1:
# Julia program to illustrate
# the use of to_indices() method
# Getting the converted tuple of indices
A = [1, 2, 3, 4];
t = (10, 20, 30, 40);
println(to_indices(A, t))
输出:
(10, 20, 30, 40)
示例 2:
# Julia program to illustrate
# the use of to_indices() method
# Getting the converted tuple of indices
A = [1, 2];
t = (5, 10, 15, 20, 25);
println(to_indices(A, t))
输出:
(5, 10, 15, 20, 25)