problems with duplicating and slicing an array

Yun Mao yunmao at gmail.com
Thu Jan 20 20:33:25 EST 2005


Hi python gurus,
  I have some questions when I'm using python numeric:

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 would be deeply appreciated!

Thanks!!!

-Y



More information about the Python-list mailing list