I have a large array and a function that returns index lists into the array, i.e.,
import numpy
n = 500
a = numpy.random.rand(n)
def get_idx(k):
# More complicated in reality
return range(n) if k > 6 else range(k)
data = a[get_idx(29)]
data = a[get_idx(30)]
# ...
A typical case is that the range is the entire array, range(n). Unfortunately, a[range(n)] scales with n while a[:] is of course constant-time. It's a pity that one cannot return : from get_idx.
What can I return from get_idx to use as an index for the entire array?