I\'ve got a large one-dimensional array of integers I need to take slices off. That\'s trivial, I\'d just do a[start:end]. The problem is that I need more of th
Similar solution like timday. Similar speed:
a = np.random.randint(0,20,1e6)
start = np.random.randint(0,20,1e4)
end = np.random.randint(0,20,1e4)
def my_fun(arr,start,end):
return arr[start:end]
%timeit [my_fun(a,i[0],i[1]) for i in zip(start,end)]
%timeit map(lambda range: a[range[0]:range[1]],zip(start,end))
100 loops, best of 3: 7.06 ms per loop
100 loops, best of 3: 6.87 ms per loop