[SciPy-User] a new enigma for a matlab user

Matthieu Brucher matthieu.brucher at gmail.com
Mon May 23 08:09:52 EDT 2011


When you do this:

Ve=Uo;

Ve and Uo point to the _same_ object. So if you want a new vector of zeros,
you have to create a new one!
If you want a compelx matrix, you can also directly say it:
Uo = np.zeros((nx,nET), dtype=np.complex128)

Matthieu

2011/5/23 midel <midel at sfr.fr>

> Hi everybody,
>
> Today I face a new mystery (for me) which seems to be linked to a
> fundamental difference between matlab and python langage...
>
> The principle of my code (its beginning) is quite simple. I create an "x"
> vector (dimension nx) and then 2 other vectors Efini_ord and Ehini which are
> gaussian functions of x.
>
> Then I want to store these vectors in two matrices Uo and Ve (dimension nx,
> 20). I do this because I will modifie the vectors 19 times and i want to
> store every step.
>
> Here is my code :
>
> import numpy as np
> import scipy as sp
>
> import matplotlib.pylab as plt
> from numpy.fft import fft,ifft
>
>
> #Fonction pour creer une gaussienne
> def supergaussnorm(x,n):
>     sga=np.exp(-x**(2*n));
>     return sga
>
> # fenetre transverse
> RES=6;
> mx=10; #taille de la fenetre
> nx=2**RES; # nombre de points
> x=np.linspace(-mx/2,mx/2,nx); #vecteur transverse
>
>
> # two different profiles
> Efini_ord=1*supergaussnorm(x,1);
> Ehini=0*(supergaussnorm(x,1));
>
> # kind of "saving data" matrices Uo and Ve
> nET=20;
> Uo=np.zeros((nx,nET))+np.zeros((nx,nET))*1j;
> Ve=Uo;
>
>
> # first iteration of data saving
> Uo[:,0]=Efini_ord;
> Ve[:,0]=Ehini; #line to be commented or not, which seems to have absolutely
> no relation with Uo
>
> # plot plot
> plt.plot(Uo[:,0],'r.')
> plt.plot(Efini_ord)
> plt.show()
>
>
> If I run this, Uo[:,0] *IS NOT* Efini_ord, but a vector of zeros...
>
> If I #comment the line :
>
> #Ve[:,0]=Ehini; #line to be commented or not, which seems to have
> absolutely no relation with Uo
>
>
> Now Uo[:,0] *IS* Efini_ord ! Everything works as if what I do with Ve has
> an influence on Uo. It is confirmed by the fact that if I create Ve by :
>
> Ve=np.zeros((nx,nET))+np.zeros((nx,nET))*1j;
>
>
> instead of
>
> Ve=Uo;
>
>
> the problem also disappears !
>
> I was used with matlab to "clone" variables as in Ve=Uo;
>
> but it looks like such writing is totally wrong in python...
>
> Can somebody explain ?
>
> Thanks !
>
> Midel
>
>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>


-- 
Information System Engineer, Ph.D.
Blog: http://matt.eifelle.com
LinkedIn: http://www.linkedin.com/in/matthieubrucher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110523/6b198a4a/attachment.html>


More information about the SciPy-User mailing list