Accessing element at a specific index in Julia – getindex() Method
The getindex() is an inbuilt function in julia which is used to construct array of the specified type. This function is also used to get the element of the array at a specific index.
Syntax: getindex(type, elements…])
Parameters:
- type: Specified type.
- elements: Specified list of elements.
Returns: It returns the constructed array of the specified type and also the element of the array at a specific index.
Example 1:
Python
println(getindex(Int8, 1 , 2 , 3 ))
println(getindex(Int16, 5 , 10 , 15 , 20 ))
println(getindex(Int32, 2 , 4 , 6 , 8 , 10 ))
|
Output:
Example 2:
Python
A = [ 1 2 3 ; 4 5 6 ]
println(getindex(A, 2 , 2 ))
println(getindex(A, 2 , 3 ))
|
Output:
Example 3:
Python
A = cat([ 1 2 ; 3 4 ],
[ "hello" "Geeks" ; "Welcome" "GFG" ],
[ 5 6 ; 7 8 ], dims = 3 )
getindex(A, 1 , 2 , 2 )
getindex(A, 1 , :, 2 )
|
Output:
Last Updated :
07 Sep, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...