Open In App

Accessing every row and column of array in Julia – colon() Operator

The Colon() is an inbuilt operator in julia which is used to indicate and access every row and column. And also this operator is used to get index of specific element in the specified array.
Example 1: 
 




# 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, :])

Output: 
 



Example 2: 
 






# 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))

Output: 
 

 

Article Tags :