can this be made faster?

A. M. Archibald peridot.faceted at
Sun Oct 8 18:08:31 CDT 2006

On 08/10/06, Robert Kern <robert.kern at> wrote:
> Bill Baxter wrote:
> > Yes, that'd be
> >    a[b] += c
> No, I'm afraid that fancy indexing does not do the loop that you are thinking it
> would (and for reasons that we've discussed previously on this list, *can't* do
> that loop). That statement reduces to something like the following:

So the question remains, is there a for-loop-free way to do this?

(This, specifically, is:
for i in range(len(b)):
where b[i] may contain repetitions.)

I didn't find one, but came to the conclusion that for loops are not
necessarily slower than fancy indexing, so the way to do this one is
just to use a for loop.

A. M. Archibald

Take Surveys. Earn Cash. Influence the Future of IT
Join's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash

More information about the Numpy-discussion mailing list