problems with duplicating and slicing an array
![](https://secure.gravatar.com/avatar/f7d9a6da452ebc094e581b751b61aa28.jpg?s=120&d=mm&r=g)
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? Thanks!!! -Y
![](https://secure.gravatar.com/avatar/5dde29b54a3f1b76b2541d0a4a9b232c.jpg?s=120&d=mm&r=g)
Simon Burton wrote:
On Thu, 20 Jan 2005 20:29:26 -0500 Yun Mao <yunmao@gmail.com> wrote:
or use numarray:
-- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
![](https://secure.gravatar.com/avatar/f351f66930a1449592dd11b288e95cb8.jpg?s=120&d=mm&r=g)
On 21.01.2005, at 02:29, Yun Mao wrote:
There are several ways to make a copy of an array. My personal preference is import copy v = copy(u) because this is a general mechanism that works for all Python objects.
y = Numeric.take(x, i) Konrad. -- ------------------------------------------------------------------------ ------- Konrad Hinsen Laboratoire Leon Brillouin, CEA Saclay, 91191 Gif-sur-Yvette Cedex, France Tel.: +33-1 69 08 79 25 Fax: +33-1 69 08 82 61 E-Mail: hinsen@llb.saclay.cea.fr ------------------------------------------------------------------------ -------
![](https://secure.gravatar.com/avatar/f351f66930a1449592dd11b288e95cb8.jpg?s=120&d=mm&r=g)
On Jan 21, 2005, at 9:48, konrad.hinsen@laposte.net wrote:
That's of course import copy v = copy.copy(u) or from copy import copy v = copy(u) Konrad. -- --------------------------------------------------------------------- Konrad Hinsen Laboratoire Léon Brillouin, CEA Saclay, 91191 Gif-sur-Yvette Cedex, France Tel.: +33-1 69 08 79 25 Fax: +33-1 69 08 82 61 E-Mail: hinsen@llb.saclay.cea.fr ---------------------------------------------------------------------
![](https://secure.gravatar.com/avatar/5dde29b54a3f1b76b2541d0a4a9b232c.jpg?s=120&d=mm&r=g)
Simon Burton wrote:
On Thu, 20 Jan 2005 20:29:26 -0500 Yun Mao <yunmao@gmail.com> wrote:
or use numarray:
-- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
![](https://secure.gravatar.com/avatar/f351f66930a1449592dd11b288e95cb8.jpg?s=120&d=mm&r=g)
On 21.01.2005, at 02:29, Yun Mao wrote:
There are several ways to make a copy of an array. My personal preference is import copy v = copy(u) because this is a general mechanism that works for all Python objects.
y = Numeric.take(x, i) Konrad. -- ------------------------------------------------------------------------ ------- Konrad Hinsen Laboratoire Leon Brillouin, CEA Saclay, 91191 Gif-sur-Yvette Cedex, France Tel.: +33-1 69 08 79 25 Fax: +33-1 69 08 82 61 E-Mail: hinsen@llb.saclay.cea.fr ------------------------------------------------------------------------ -------
![](https://secure.gravatar.com/avatar/f351f66930a1449592dd11b288e95cb8.jpg?s=120&d=mm&r=g)
On Jan 21, 2005, at 9:48, konrad.hinsen@laposte.net wrote:
That's of course import copy v = copy.copy(u) or from copy import copy v = copy(u) Konrad. -- --------------------------------------------------------------------- Konrad Hinsen Laboratoire Léon Brillouin, CEA Saclay, 91191 Gif-sur-Yvette Cedex, France Tel.: +33-1 69 08 79 25 Fax: +33-1 69 08 82 61 E-Mail: hinsen@llb.saclay.cea.fr ---------------------------------------------------------------------
participants (7)
-
Alan G Isaac
-
Chris Barker
-
konrad.hinsen@laposte.net
-
Simon Burton
-
Stephen Walton
-
Travis Oliphant
-
Yun Mao