# [SciPy-user] Numpy : in place moving data strange behaviour

Samuel GARCIA sgarcia@olfac.univ-lyon1...
Fri Aug 1 03:47:13 CDT 2008

```Hi list,
I have a strange behaviour of numpy if I try to move in place
a part of my array in an other place of the array.
For 1D or for 2D there is not the same behaviour.
The solution is of course copying the part I have move of thhe array.
See the code :

from scipy import *

# for 1D
a = arange(10)
print a # a = [0 1 2 3 4 5 6 7 8 9]
a[0:7] = a[3:10]
print a # OK : a = [3 4 5 6 7 8 9 7 8 9]

a = arange(10)
print a
a[3:10] = a[0:7]
print a # OK a = [0 1 2 0 1 2 3 4 5 6]

# for 2D
a = concatenate( (arange(10)[newaxis,:] , arange(10)[newaxis,:]) )
print a
#[[0 1 2 3 4 5 6 7 8 9]
# [0 1 2 3 4 5 6 7 8 9]]
a[:,0:7] = a[:,3:10]
print a
#OK a=
# [[3 4 5 6 7 8 9 7 8 9]
# [3 4 5 6 7 8 9 7 8 9]]

a = concatenate( (arange(10)[newaxis,:] , arange(10)[newaxis,:]) )
print a
a[:,3:10] = a[:,0:7]
print a
# Not expected a =
#[[0 1 2 0 1 2 0 1 2 0]
# [0 1 2 0 1 2 0 1 2 0]]

# solution copy all the array :
a = concatenate( (arange(10)[newaxis,:] , arange(10)[newaxis,:]) )
a[:,3:10] = a[:,0:7].copy()
print a
# OK a =
#[[0 1 2 0 1 2 3 4 5 6]
# [0 1 2 0 1 2 3 4 5 6]]

Any explanation  ?

Thank

Samuel

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Samuel Garcia
Laboratoire de Neurosciences Sensorielles, Comportement, Cognition.
CNRS - UMR5020 - Universite Claude Bernard LYON 1
Equipe logistique et technique
50, avenue Tony Garnier
69366 LYON Cedex 07
FRANCE
Tél : 04 37 28 74 64
Fax : 04 37 28 76 01
http://olfac.univ-lyon1.fr/unite/equipe-07/
http://neuralensemble.org/trac/OpenElectrophy
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

```