[Numpy-discussion] problems with duplicating and slicing an array
Simon Burton
simon at arrowtheory.com
Thu Jan 20 17:45:42 EST 2005
On Thu, 20 Jan 2005 20:29:26 -0500
Yun Mao <yunmao at gmail.com> wrote:
> Hi everyone,
> I have two questions:
> 1. When I do v = u[:, :], it seems u and v still point to the same
> memory. e.g. When I do v[1,1]=0, u[1,1] will be zero out as well.
> What's the right way to duplicate an array? Now I have to do v =
> dot(u, identity(N)), which is kind of silly.
v = na.array(u)
>
> 2. Is there a way to do Matlab style slicing? e.g. if I have
> i = array([0, 2])
> x = array([1.1, 2.2, 3.3, 4.4])
> I wish y = x(i) would give me [1.1, 3.3]
> Now I'm using map, but it gets a little annoying when there are two
> dimensions. Any ideas?
have a look at the "take" method.
Simon.
More information about the NumPy-Discussion
mailing list