[Numpy-discussion] filling an alice of array of object with a reference to an object that has a __getitem__ method

Olivier Delalleau shish@keba...
Mon Jan 9 09:39:21 CST 2012


Oh, sorry, I hadn't paid enough attention to the way you are indexing A: if
you are using an array to index, it creates a copy, so using ".fill" will
fill the copy and you won't see the result.
Instead, use A[0:3], A[3:6], etc.

-=- Olivier


2012/1/9 "David Köpfer" <dkoepfer@gmx.de>

> Hi Oliver,
>
> thank you very much for your reply, sadly it is not working as you and I
> hoped. The array still stays at None even after the code.
>
> I've also tried A[X] = [MyObject(...)]*len(X) but that just results in a
> Memory error.
>
> So is there really no way to avoid this broadcasting?
>
> David
>
>
> -------- Original-Nachricht --------
> > Datum: Sun, 8 Jan 2012 16:16:33 -0500
> > Von: Olivier Delalleau <shish@keba.be>
> > An: Discussion of Numerical Python <numpy-discussion@scipy.org>
> > Betreff: Re: [Numpy-discussion] filling an alice of array of object with
> a reference to an object that has a __getitem__ method
>
> > You could try A[...].fill(MyObject(...)). I haven't tried it myself, so
> > not
> > sure it would work though...
> >
> > -=- Olivier
> >
> > 2012/1/6 "David Köpfer" <dkoepfer@gmx.de>
> >
> > > Dear numpy community,
> > >
> > > I'm trying to create an array of type object.
> > >
> > > A = empty(9, dtype=object)
> > > A[ array(0,1,2) ] = MyObject(1)
> > > A[ array(3,4,5) ] = MyObject(2)
> > > A[ array(6,7,8) ] = MyObject(3)
> > >
> > > This has worked well until MyObject has gotten an __getitem__ method.
> > Now
> > > python (as it is usually supposed to) assigns A[0] to MyObject(1)[0],
> > [1]
> > > to MyObject(1)[1] and so on.
> > >
> > > Is there any way to just get a reference of the instance of MyObject
> > into
> > > every entry of the array slice?
> > >
> > > Thank you for any help on this problem
> > > David
> > > _______________________________________________
> > > NumPy-Discussion mailing list
> > > NumPy-Discussion@scipy.org
> > > http://mail.scipy.org/mailman/listinfo/numpy-discussion
> > >
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120109/787b5e5a/attachment.html 


More information about the NumPy-Discussion mailing list