访问 Julia 中数组的每一行和每一列 - 冒号()运算符
Colon()是 julia 中的内置运算符,用于指示和访问每一行和每一列。此运算符还用于获取指定数组中特定元素的索引。
示例 1:
Python
# Julia program to illustrate
# the use of Colon (:) operator
# Indicating every row and column
Array1 = [1 2 "Hello"; 3 4 "Geeks"]
println(Array1[:, 3])
println(Array1[1, :])
Python
# Julia program to illustrate
# the use of Colon (:) operator
# Accessing every row and column
Array1 = cat([1 2; 3 4],
["hello" "Geeks"; "Welcome" "GFG"],
[5 6; 7 8], dims = 3)
println(Array1[:, :, 3])
# Using getindex with colon operator
println(getindex(Array1, 1, :, 2))
输出:
示例 2:
Python
# Julia program to illustrate
# the use of Colon (:) operator
# Accessing every row and column
Array1 = cat([1 2; 3 4],
["hello" "Geeks"; "Welcome" "GFG"],
[5 6; 7 8], dims = 3)
println(Array1[:, :, 3])
# Using getindex with colon operator
println(getindex(Array1, 1, :, 2))
输出: