[SciPy-User] [SciPy-user] ValueError: arrays must have same number of dimensions

Jorge E. ´Sanchez Sanchez hnry2k@hotmail....
Thu Jun 28 10:48:17 CDT 2012


Hi,

it seems to me that you don't know that loops in python end before the last index value of the loop,
you just need to do something like:
 Np1 = N+1
for j in range (1, Np1):

HTH
Best Regards
Jorge


> Date: Thu, 28 Jun 2012 08:32:47 -0700
> From: surfcast23@gmail.com
> To: scipy-user@scipy.org
> Subject: [SciPy-User] [SciPy-user] ValueError: arrays must have same number	of dimensions
> 
> 
> Hi I am trying to translate a Matlab code from Trefethen's Spectral Methods
> in MATLAB to Python. I am running into a problem with numpy.concatenate
> wanting the arrays to have the same number of dimensions.
> Here is part of the Matlab code that I am rewriting 
> 
> 
> N = 512; h = 2*pi/N; x = h*(1:N); t = 0; dt = h/4;
> a = .1;
> c = a + sin (x-1).^2;
> v = exp(-100*(x-1).^2); vold = exp(-100*(x-a*dt-1).^2);
> 
> column = [0 .5*(-1).^(1:N-1).*cot((1:N-1)*h/2)];
> D = toeplitz(column,-column);
> 
> % Time-stepping by leap frog formula:
> tmax = 15; tplot = .15; clf, drawnow, set(gcf,'renderer','zbuffer')
> plotgap = round(tplot/dt); dt = tplot/plotgap;
> nplots = round(tmax/tplot);
> data = [v; zeros(nplots,N)]; tdata = t;
> 
> 
> What I am trying in Python
> 
> for j in range(1,N):
>  tmax = 15;   
>  tplot = .15;
>  h = 2*pi/N;
>  dt = h/4; 
>  nplots = around(tmax/tplot);
>  plotgap = around(tplot/dt);
>  dt = tplot/plotgap;  
>  x = h*arange(1,N);
>  c = a+np.sin(x-1)**2;
>  v = exp(-100*(x-1)**2);
>  vold = exp(-100*(x-a*dt-1)**2);
>  
>  column = ((0.5*(-1)**arange(1,N-1))*cotdg(arange(1,N-1))*(h/2));
>  D = toeplitz(column,-column);
>  
>  k = np.zeros(((nplots,N)));
>  data = np.concatenate((v, k),axis = 0);
>  tdata = t;
> 
> 
> I have highlighted the vectors in question.
> v.shape gives (511,)
> 
> k.shape gives (100, 512)
> 
> I would appreciate any help with this. Thank you!
> 
> -- 
> View this message in context: http://old.nabble.com/ValueError%3A-arrays-must-have-same-number-of-dimensions-tp34086886p34086886.html
> Sent from the Scipy-User mailing list archive at Nabble.com.
> 
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20120628/3cd383bf/attachment.html 


More information about the SciPy-User mailing list