Given a numpy array a, is there any alternative to
a[-1]
to get the last element?
The idea is to have some aggregating numpy method as
np.last(a)
that could be passed to a function to operate on a numpy array:
import numpy as np
def operate_on_array(a: np.array, np_method_name: str):
method = getattr(np, np_method_name)
return method(a)
This would work for methods such as np.mean, np.sum but I have not been able to find if there is some numpy method name that would return the last or first element of the array.
What about a lambda?