The way to βstartβ the array you want is:
arr = np.empty((0,3), int)
This is an empty array, but it has the correct dimension.
>>> arr array([], shape=(0, 3), dtype=int64)
Then be sure to add the 0 axis:
arr = np.append(arr, np.array([[1,2,3]]), axis=0) arr = np.append(arr, np.array([[4,5,6]]), axis=0)
But, @jonrsharpe is right. In fact, if you are going to add to the loop, it would be much faster to add to the list, as in the first example, and then convert to a numpy array at the end, since you really do not use numpy as intended during the loop:
In [210]: %%timeit .....: l = [] .....: for i in xrange(1000): .....: l.append([3*i+1,3*i+2,3*i+3]) .....: l = np.asarray(l) .....: 1000 loops, best of 3: 1.18 ms per loop In [211]: %%timeit .....: a = np.empty((0,3), int) .....: for i in xrange(1000): .....: a = np.append(a, 3*i+np.array([[1,2,3]]), 0) .....: 100 loops, best of 3: 18.5 ms per loop In [214]: np.allclose(a, l) Out[214]: True
The multilingual way to do this depends on your application, but it will be more like:
In [220]: timeit n = np.arange(1,3001).reshape(1000,3) 100000 loops, best of 3: 5.93 Β΅s per loop In [221]: np.allclose(a, n) Out[221]: True