[Numpy-discussion] Index Array Performance

Pauli Virtanen pav@iki...
Tue Feb 14 17:46:39 CST 2012


15.02.2012 00:23, Marcel Oliver kirjoitti:
[clip]
> Thanks for all the replies.  Playing a bit with timeit, it is clear
> that it cannot just be the overhead of checking the type of the index
> array, as the overhead grows very roughly propertional to the size of
> the index array, but remains independent of the size of the indexed
> array.
> 
> In [1]: a=arange(1000000)
> 
> In [2]: i = arange(10)
> 
> In [3]: timeit a[i]
> 100000 loops, best of 3: 1.95 us per loop
> 
> In [4]: i = arange(100)
> 
> In [5]: timeit a[i]
> 100000 loops, best of 3: 4.07 us per loop

I think the linear growth here is expected, as

i = arange(n)
a[i].shape == i.shape

It's probably possible to cut the overhead, though.

-- 
Pauli Virtanen



More information about the NumPy-Discussion mailing list