[SciPy-user] Concatenating 1D arrays

Ryan Krauss ryanlists at gmail.com
Wed Feb 8 11:31:04 CST 2006


Are hstack and vstack new to numpy?  They are pretty cool.

On 2/8/06, Robert Kern <robert.kern at gmail.com> wrote:
> Rudolph van der Merwe wrote:
> > What is the Numpy prefered way of recursively concatenating 1D arrays
> > (vectors) into a 2D array (matrix)?
> >
> > I'm trying to convert the following Matlab code to Python:
> >
> > x=[];
> > y=[];
> > for k=1:N,
> >     c = get_column_vector_from_somewhere()
> >     r = get_row_vector_from_somewhere()
> >     x = [x c]
> >     y = [y; r]
> > end
>
> Assuming that you don't actually know N (in which case Johannes' second example
> is appropriate),
>
> x = []
> y = []
>
> while have_more_vectors():
>     x.append(get_column_vector_from_somewhere())
>     y.append(get_row_vector_from_somewhere())
>
> x = hstack(x)
> y = vstack(y)
>
> --
> Robert Kern
> robert.kern at gmail.com
>
> "In the fields of hell where the grass grows high
>  Are the graves of dreams allowed to die."
>   -- Richard Harter
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user
>



More information about the SciPy-user mailing list