Getting last index of a collection in Julia – lastindex() Methods
The lastindex()
is an inbuilt function in julia which is used to return the last index of the specified collection. If a dimension d is given, return the last index of collection along dimension d.
Syntax:
lastindex(collection)
or
lastindex(collection, d)
Parameters:
- collection: Specified collection.
- b: Specified dimension.
Returns: It returns the last index of the specified collection. If a dimension d is given, return the last index of collection along dimension d.
Example 1:
println(lastindex( 0 ))
println(lastindex([ 1 , 2 , 3 ]))
println(lastindex([ 2 4 ; 5 6 ]))
println(lastindex([ 3 ; 5 ; 7 ; 9 ]))
|
Output:
Example 2:
println(lastindex(rand( 1 , 2 , 3 , 4 ), 1 ))
println(lastindex(rand( 1 , 2 , 3 , 4 ), 2 ))
println(lastindex([ 1 , 2 , 3 ], 2 ))
println(lastindex([ 2 4 ; 6 8 ], 2 ))
println(lastindex([ 2 ; 4 ; 6 ; 8 ], 2 ))
println(lastindex(cat([ 1 2 ; 3 4 ], [ 5 6 ; 7 8 ], [ 2 2 ; 3 4 ], dims = 3 );))
|
Output:
Last Updated :
26 Mar, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...