Open In App

Getting last index of a collection in Julia – lastindex() Methods

Last Updated : 26 Mar, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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:




# Julia program to illustrate 
# the use of lastindex() method
   
# Getting the last index of the specified collection.
println(lastindex(0))
println(lastindex([1, 2, 3]))
println(lastindex([2 4; 5 6]))
println(lastindex([3; 5; 7; 9]))


Output:

Example 2:




# Julia program to illustrate 
# the use of lastindex() method
   
# Getting the last index of the specified 
# collection. If a dimension d is given, 
# return the last index of collection 
# along dimension d.
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:



Similar Reads

Getting first index of a collection in Julia - firstindex() Methods
The firstindex() is an inbuilt function in julia which is used to return the first index of the specified collection. If a dimension d is given, return the first index of collection along dimension d. Syntax: firstindex(collection) or firstindex(collection, d) Parameters: collection: Specified collection. b: Specified dimension. Returns: It returns
1 min read
Getting copy of filtered collection in Julia - filter() and filter!() Methods
The filter() is an inbuilt function in julia which is used to return a copy of the specified abstract array with different types of filtration performed. These all operation are illustrated with below examples. Syntax: filter(f, a::AbstractArray) or filter(f, d::AbstractDict) or filter(f, itr::SkipMissing{<:AbstractArray})Parameters: f: Specifie
3 min read
Getting first and last set of elements in Julia - front() and tail() Methods
The front() is an inbuilt function in julia which is used to return a tuple consisting of all but the last component of x, where x is the specified tuple. Syntax: front(x::Tuple)::Tuple Parameters: x::Tuple: Specified tuple. Returns: It returns a tuple consisting of all but the last component of x, where x is the specified tuple. Example: # Julia p
2 min read
Getting last element of an array in Julia - last() Method
The last() is an inbuilt function in julia which is used to return the last element of the specified iterable collection. Syntax: last(coll) Parameters: coll: Specified iterable collection. Returns: It returns the last element of the specified iterable collection. Example 1: # Julia program to illustrate # the use of last() method # Getting the las
1 min read
Apply operations on a collection in Julia - map() and map!() Methods
The map() is an inbuilt function in julia which is used to transform the specified collection by using specified operation to each element. Syntax: map(f, c...) Parameters: f: Specified operation. c: Specified collection. Returns: It returns the transformed elements. Example: # Julia program to illustrate # the use of map() method # Getting the tra
2 min read
Replacing elements of a collection in Julia - replace() and replace!() Methods
The replace() is an inbuilt function in julia which is used to return a copy of the specified array with different types of replacement. These all operations are illustrated with below examples. Syntax: replace(A, old_new::Pair...; count::Integer) or replace(new::Function, A; count::Integer) Parameters: A: Specified array. old_new::Pair: Specified
3 min read
Getting an array of all items of a collection in Julia - collect() Method
The collect() is an inbuilt function in julia which is used to return an array of all items in the specified collection or iterator. Syntax: collect(collection) or collect(element_type, collection) Parameters: collection: Specified collection or iterator. element_type: Specified type of elements. Returns: It returns an array of all items in the spe
1 min read
Getting lowest and highest value of a Data type in Julia - typemin() and typemax() Methods
The typemin() is an inbuilt function in julia which is used to return the lowest value representable by the specified numeric DataType. Syntax: typemin(T) Parameters: T: Specified numeric DataType. Returns: It returns the lowest value representable by the specified numeric DataType. Example 1: # Julia program to illustrate # the use of typemin() me
1 min read
Getting inverse sine and inverse hyperbolic sine in Julia - asin(), asinh() and asind() Methods
The asin() is an inbuilt function in julia which is used to calculate inverse sine of the specified value and output is in radians. Syntax: asin(x) Parameters: x: Specified values. Returns: It returns the calculated inverse sine of the specified value and output is in radians. Example: # Julia program to illustrate # the use of asin() method # Gett
2 min read
Getting inverse cosine and inverse hyperbolic cosine in Julia - acos(), acosh() and acosd() Methods
The acos() is an inbuilt function in julia which is used to calculate inverse cosine of the specified value and output is in radians. Syntax: acos(x) Parameters: x: Specified values. Returns: It returns the calculated inverse cosine of the specified value and output is in radians. Example: # Julia program to illustrate # the use of acos() method #
2 min read
Article Tags :