can this be made faster?

A. M. Archibald peridot.faceted at gmail.com
Sun Oct 8 19:08:31 EDT 2006


On 08/10/06, Robert Kern <robert.kern at gmail.com> 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)):
    a[b[i]]+=c[i]
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 SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV




More information about the NumPy-Discussion mailing list