[Numpy-discussion] problems with duplicating and slicing an array

Yun Mao yunmao at gmail.com
Thu Jan 20 17:32:26 CST 2005

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.

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?



More information about the Numpy-discussion mailing list