I need to create a numpy array of N elements, but I want to access the
array with an offset Noff, i.e. the first element should be at Noff and
not at 0. In C this is simple to do with some simple pointer arithmetic, i.e.
I malloc the array and then define a pointer and shift it appropriately.
Furthermore, I do not want to allocate N+Noff elements, but only N elements.
Now for numpy there are many methods that come to my mind:
(1) define a wrapper function to access the array
(2) overwrite the [] operator
(3) etc
But what is the fastest method to realize this?
Thanks a lot!
Mark
You’ve already given (1) and (2) as both more or less sensible methods. To test speed for these kind of things try
timeitmagic function inipython. Example usage:On my machine I get output from timeit
10000000 loops, best of 3: 193 ns per loop