can this be made faster?

Bill Baxter wbaxter at gmail.com
Sun Oct 8 02:17:29 EDT 2006


Yeh, I spoke too soon.  Tried a little example and it seemed to work.
I don't get a traceback here, but your example doesn't work as expected, either.
I get [1,1] as the answer with numpy 1.0rc1.  Probably it should be an
exception, though.

It seems to work if len(b)<=len(a)  and when no indices are repeated in b.

--bb

On 10/8/06, Daniel Mahler <dmahler at gmail.com> wrote:
> Thanks Bill.
> Thats what I was hoping for,
> but I get
>
> >>> a
> array([0, 0])
> >>> b
> array([0, 1, 0, 1, 0])
> >>> c
> array([1, 1, 1, 1, 1])
> >>> a[b]+=c
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> IndexError: invalid index
>
> whereas i would like to get
>
> array([3, 2])
>
>
>
> On 10/8/06, Bill Baxter <wbaxter at gmail.com> wrote:
> > Yes, that'd be
> >    a[b] += c
> >
> > On 10/8/06, Daniel Mahler <dmahler at gmail.com> wrote:
> > > Is there a 'loop free' way to do this in Numeric
> > >
> > > for i in arange(l):
> > >    a[b[i]]+=c[i]
> > >
> > > where l == len(b) == len(c)
> > >
> > > thanks
> > > Daniel
> >
> > -------------------------------------------------------------------------
> > 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
> > _______________________________________________
> > Numpy-discussion mailing list
> > Numpy-discussion at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/numpy-discussion
> >
>
> -------------------------------------------------------------------------
> 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
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>

-------------------------------------------------------------------------
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