[SciPy-user] Concatenating 1D arrays

Rudolph van der Merwe rudolphv at gmail.com
Wed Feb 8 04:16:15 CST 2006


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

In other words, x and y get initialized to empty arrays and then grown
in-place. x is grown (appended) column wise with vectors c and y is
appended (row wise) with vectors r.

In Numpy (numpy), how do I initialize an empty array with the correct
dimensions which can then be used with functions like: column_stack(),
concatenate(), etc. ?




--
Rudolph van der Merwe



More information about the SciPy-user mailing list