How to Concatenate Array Using Numpy

To Concatenate array in numpy, we can use Numpy.concatenate function. Here are some examples:

Example 1: Concatenate array by row

>>> import numpy as np
>>> a = np.array([[1, 2], [3, 4]])
>>> b = np.array([[5, 6]])
>>> np.concatenate((a, b), axis=0)
array([[1, 2],
[3, 4],
[5, 6]])

Notice: set axis=0 and the size of array column is the same

Example 2: Concatenate array by column

‚Äč>>> import numpy as np
>>> a = np.array([[1, 2], [3, 4]])
>>> b = np.array([[5, 6]])
>>> np.concatenate((a, b.T), axis=1)
array([[1, 2, 5],
[3, 4, 6]])

Notice:set axis=1 and the size of array row is the sam

,