[Numpy-discussion] Inplace index suprise
Thu Mar 20 13:56:40 CDT 2008
On 20/03/2008, Gael Varoquaux <firstname.lastname@example.org> wrote:
> On Thu, Mar 20, 2008 at 06:17:44PM +0000, James Philbin wrote:
> > Hi,
> > > This cannot work, because the inplace operation does not
> > > take place as a for loop.
> > Well, this would be fine if I was assigning the values to tempories as
> > you suggest. However, the operation should be performed inplace and
> > this is what I don't understand - why is there no for loop? I think
> > the semantics of these inplace indexed operations is intuitively quite
> > clear and numpy doesn't follow this intuition. Would there be any
> > interest in changing this behaviour in numpy?
> I think this is technicaly impossible from the way numpy works. This
> breaks the numpy model that every operation is global on the array.
It is quite reasonable from a least-surprise point of view.
Unfortunately it can't really be done because of the way python
implements augmented assignments. If I'm not mistaken, numpy's
histogram function can be used to accomplish this particular thing.
> > > This is a FAQ.
> > Sorry if i'm rehashing old ground, but the closest thing I could find
> > to a numpy faq is here: http://www.scipy.org/FAQ. There seems to be no
> > mention of this issue there.
> Sorry if I came out harsh, I certainly didn't want to implie that you
> were expecting something wrong, just that this thing was tricking people.
I added it to that FAQ, along with the explanation I got when I asked
the same question:
More information about the Numpy-discussion