I'm trying to use and accelerate fancy indexing to "join" two arrays and sum over one of results' axis.
Something like this:
$ ipython
In [1]: import numpy as np
In [2]: ne, ds = 12, 6
In [3]: i = np.random.randn(ne, ds).astype('float32')
In [4]: t = np.random.randint(0, ds, size=(1e5, ne)).astype('uint8')
In [5]: %timeit i[np.arange(ne), t].sum(-1)
10 loops, best of 3: 44 ms per loop
Is there a simple way to accelerate the statement in In [5]
? Should I go with OpenMP and something like scipy.weave
or Cython
's prange
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…