[Numpy-discussion] Subarray with with arbitrary index?
Paul F. Dubois
paul at pfdubois.com
Sat Aug 18 11:29:23 CDT 2001
I'm afraid that you have to do put using one-d indices. But you do *not*
have to try to ravel the source. I.e., the first arg is just the name of
the array.
>>> from Numeric import *
>>> x=array([[1,2,3],[4,5,6]])
>>> x
array([[1, 2, 3],
[4, 5, 6]])
>>> put(x,[0,4],[100,200])
>>> x
array([[100, 2, 3],
[ 4, 200, 6]])
>>>
-----Original Message-----
From: Huaiyu Zhu [mailto:huaiyu_zhu at yahoo.com]
Sent: Friday, August 17, 2001 11:36 PM
To: Paul F. Dubois
Cc: John J. Lee
Subject: RE: [Numpy-discussion] Subarray with with arbitrary index?
Thanks, John and Paul. That is what I was looking for.
It did not occur to me to look for verbs put and take, rather than words
line sub- index, slice and so on. Maybe puting some of these words in
the manual could help people doing a search?
Now that this made the most costly part of my program about seven times
faster, other problems become more prominent. One of such question is:
How do we do it on more than one axis?
Suppose a is a 2d array. Then put(a[1,:], b, c) works, but put(a[:,1],
b,
c) complains about the first argument not a continuous array. Doing
transpose does not help. So do I guess it right that this is
implemented
only in the representation of a linear array?
If so, there would be no hope of using put(a, ([2, 4], [1,2]), v) or
even
more exotic ones like using += on an arbitray subgrid?
Regards,
Huaiyu
On Fri, 17 Aug 2001, Paul F. Dubois wrote:
> John is right:
> >>> a=Numeric.arange(8)
> >>> b=Numeric.array([2,3,5])
> >>> c=Numeric.arange(3)+100
> >>> Numeric.put(a,b,c)
> >>> print a
> [ 0 1 100 101 4 102 6 7]
>
> Thanks for pointing out that I had left allclose out of the Numeric
part of
> the manual. I did it in the MA part and then forgot. I'm fixing it
now. BTW:
> There are changenotes at source forge that are sometimes ahead of the
> manual.
>
> -----Original Message-----
> From: numpy-discussion-admin at lists.sourceforge.net
> [mailto:numpy-discussion-admin at lists.sourceforge.net]On Behalf Of John
> J. Lee
> Sent: Friday, August 17, 2001 6:36 AM
> To: Huaiyu Zhu
> Cc: numpy-discussion at lists.sourceforge.net
> Subject: Re: [Numpy-discussion] Subarray with with arbitrary index?
>
>
> On Thu, 16 Aug 2001, Huaiyu Zhu wrote:
>
> > Hi,
> >
> > Is it possible to assign to a subarray with arbitrary index?
> >
> > Suppose I have three arrays
> >
> > a = arange(8)
> > b = array([2, 3, 5])
> > c = arange(3)+100
> >
> > I want a function f, such that calling f(a, b, c) would change a to
> >
> > [0 1 100 101 4 102 6 7]
>
> f = Numeric.put
> f(a, b, c)
>
> put used to be in Python, but it's been in C since some release
17.x.x, I
> think.
>
> I have a sinking feeling that I must have missed something (no
interpreter
> here to check it works)...
>
> BTW, a week ago I noticed that I had reinvented the wheel in
rewriting, in
> an uglier and less efficient form, Numeric.allclose (hope I got the
name
> right). As far as I can see, it isn't listed in the manual. Did I
miss
> it? All it would need is the docstring copying over.
>
>
> John
>
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> http://lists.sourceforge.net/lists/listinfo/numpy-discussion
>
More information about the Numpy-discussion
mailing list