thouis / numpy-trac-migration

numpy Trac to github issues migration
2 stars 3 forks source link

Speed up N-D Boolean indexing (Trac #274) #4077

Open thouis opened 12 years ago

thouis commented 12 years ago

Original ticket http://projects.scipy.org/numpy/ticket/274 on 2006-09-06 by atmention:teoliphant, assigned to unknown.

Currently N-D Boolean indexing works by creating intermediate integer index arrays for N>1. This should be avoided when possible so that Boolean indexing is faster for N>1.

thouis commented 12 years ago

Milestone changed to 1.1 by atmention:alberts on 2007-05-12

thouis commented 12 years ago

Milestone changed to Unscheduled by atmention:cournape on 2009-03-02

thouis commented 12 years ago

atmention:mwiebe wrote on 2011-03-23

Here's a small benchmark illustrating the problem:

In [1]: import numpy as np

In [2]: np.__version__
Out[2]: '2.0.0.dev-7219ac2'

In [3]: a = np.random.random(100000)

In [4]: amask = a > 0.9

In [5]: b = a.reshape(100,1000)

In [6]: bmask = amask.reshape(100,1000)

In [7]: timeit a[amask]
1000 loops, best of 3: 787 us per loop

In [8]: timeit b[bmask]
1000 loops, best of 3: 1.22 ms per loop