Problem
I want to concatenate multiple 2-dimensional numpy arrays having shape (1, N).
As an example, let's say I want to concatenate multiple np.array([1, 1]).
My inefficient solution
A very inefficient way to do this is the following:
main_array = np.array([])
for i in range(0, 10):
if main_array.size == 0:
# necessary step otherwise the first time the two arrays have different shapes
main_array = np.expand_dims(np.array([1, 1]), 0)
else:
main_array = np.concatenate((main_array, np.expand_dims(np.array([1, 1]), 0)))
The result, as expected, is a numpy array having shape (10, 2).
Question
How can I make this operation more efficient?
EDIT:
In my example, I add 10 times the same array for the sake of simplicity. This is probably confusing since I am actually looking for an efficient way to add any array and not necessarily the same one.
np.vstack([list of arrays])?