📌  相关文章
📜  在 Julia 中获取数组的最后一个元素 – last() 方法

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

last()是 julia 中的一个内置函数,用于返回指定可迭代集合的最后一个元素。

示例 1:

# Julia program to illustrate 
# the use of last() method
   
# Getting the last element of 
# the specified iterable collection
# or 1D array
println(last(1:2:3))
println(last(5:10))
println(last([3, 5, 7, 9]))
println(last([2, 4, 6, 8]))

输出:

3
10
9
8

示例 2:

# Julia program to illustrate 
# the use of last() method
   
# Getting the last element of 
# the specified 2D and 3D array
println(last([3 5; 7 9]))
println(last(["a" "b"; "c" "d"]))
println(last(cat([1 2; 3 4], [5 6; 7 8],
                 [2 2; 3 4], dims = 3)))
println(last(cat(["a" "b"; "c" "d"], 
                 ["e" "f"; "g" "h"], 
                 ["i" "j"; "k" "l"], dims = 3)))

输出: