[Matrix-SIG] whats the best way to combine 1D arrays into 2D arrays?

Arne Keller arne@requin.ppm.u-psud.fr
Thu, 08 Oct 1998 11:28:08 +0200


eric jones wrote:
> 
> Hello,
> 
> I'd like to take two 1D arrays and combine them as the rows of a 2D array.
> For example, in Matlab, the following works:
> 
> x=1:3;
> y=1:3;
> z=[x;y]
> 
> so that
> z= [[1,2,3]
>       [1,2,3]]
> 
> The way I've done this in NumPy is:
> 
> x = arange(1,4)
> y = arange(1,4)
> z = concatenate( (reshape(x,[1,-1]),reshape(y,[1,-1]) ) )
> 
> Is there a more compact way of doing this?
> 
> thanks,
> eric
> 
> _______________________________________________
> Matrix-SIG maillist  -  Matrix-SIG@python.org
> http://www.python.org/mailman/listinfo/matrix-sig


I use the following:

>>> a = array([1,2,3,4,5])
>>> b = array([6,7,8,9,10])
c = array((a,b))
>>> c
array([[ 1,  2,  3,  4,  5],
       [ 6,  7,  8,  9, 10]])


-- 
Arne Keller
Laboratoire de Photophysique Moleculaire du CNRS.
Universite de Paris-Sud, 91405 Orsay Cedex, France.
tel.: (33) 1 69 15 82 83 -- fax. : (33) 1 69 15 67 77