# Append a NumPy array to a NumPy array

### Question

I have a numpy_array. Something like `[ a b c ]`.

And then I want to append it into another NumPy array (just like we create a list of lists). How do we create an array of NumPy arrays containing NumPy arrays?

I tried to do the following without any luck

``````>>> M = np.array([])
>>> M
array([], dtype=float64)
>>> M.append(a,axis=0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'numpy.ndarray' object has no attribute 'append'
>>> a
array([1, 2, 3])
``````
1
120
3/22/2016 6:57:54 PM

``````In : import numpy as np

In : a = np.array([[1, 2, 3], [4, 5, 6]])

In : b = np.array([[9, 8, 7], [6, 5, 4]])

In : np.concatenate((a, b))
Out:
array([[1, 2, 3],
[4, 5, 6],
[9, 8, 7],
[6, 5, 4]])
``````

or this:

``````In : a = np.array([1, 2, 3])

In : b = np.array([4, 5, 6])

In : np.vstack((a, b))
Out:
array([[1, 2, 3],
[4, 5, 6]])
``````
153
8/2/2016 5:27:02 PM

Well, the error message says it all: NumPy arrays do not have an `append()` method. There's a free function `numpy.append()` however:

``````numpy.append(M, a)
``````

This will create a new array instead of mutating `M` in place. Note that using `numpy.append()` involves copying both arrays. You will get better performing code if you use fixed-sized NumPy arrays.