[SciPy-user] concatenation of arrays woes !!

Gary Pajer pajer at iname.com
Tue May 4 08:26:25 CDT 2004


----- Original Message ----- 
From: "Karthikesh Raju" <karthik at james.hut.fi>
To: <scipy-user at scipy.net>
Sent: Tuesday, May 04, 2004 4:10 AM
Subject: [SciPy-user] concatenation of arrays woes !!


>
> Hi All,
>
> is it possible to concatenate arrays along the column,
>
> A[:,1:5] = concatenate(a,b,c)
> a is 2x1, b 2x1, c 1x1
>
> i have been trying to convert the following matlab code and this is my
> stumbling block for several months :(
>
> K = 3
> CL = 5
> L = 2
> d -- (K,L) in the range (0,CL)
> codes -- (K,CL)
> window = 1
> s = codes'
>
> output S -(CL*window,K*L*(window+1)) matrix
>
> for k = 1:K
> for l = 1:L
>     S(:,1+(window+1)*(l-1)+(window+1)*L*(k-1)) =
>            [s(CL-d(k,l)+1:CL,k);
zeros(CL*(window-1),1);zeros(CL-d(k,l),1)]
>     S(:,(window+1)*1+(window+1)*L*(k-1)) =
>            [zeros(d(k,l),1);zeros(CL*(window-1),1);s(1:CL-d(k,l),k)]
>     for n=2:window
>         S(:,n+(window+1)*(l-1)+(numbits+1)*L*(k-1)) =
>            [zeros(d(k,l),1); zeros(CL*(n-2),1);
> s(:,k);zeros((window-n)*CL+CL-d(k,l),1)]
>     end
> end
> end
>
> --------------------
>
> This module has been my stumbling block for the last 2 months, had no
> problems with matlab, here i have all kinds of concatination woes. Please
> give me pointers on how to achieve such concatenations,
>
> thanks a lot
>
> regards
> karthik



I'm still not sure what you are trying to achieve.  If you post a minimal
contrived example of what you are trying to do instead of a clip from the
middle of your code it would be easier to figure out.

But have you explored r_[ ]  and c_[ ] ?   ('c' for column, 'r' for row)
These constructions are designed to aid concatenation:

>>> from scipy import *
>>> x=array([1,2])
>>> y=array([3,4])

>>> c_[x,y]
array([1, 2, 3, 4])

>>> c_[x[:,NewAxis],y[:,NewAxis]]
array([[1, 3],
       [2, 4]])

>>> r_[x[:,NewAxis],y[:,NewAxis]]
array([[1],
       [2],
       [3],
       [4]])


hth,
gary



More information about the SciPy-user mailing list