# 4.17. Array Concatenation

## 4.17.1. 1-dimensional Array

import numpy as np

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

np.concatenate(a, b)
# TypeError: only integer scalar arrays can be converted to a scalar index

np.concatenate((a, b))
# array([1, 2, 3, 4, 5, 6])

import numpy as np

a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.array([7, 8, 9])

np.concatenate((a, b, c))
# array([1, 2, 3, 4, 5, 6, 7, 8, 9])

import numpy as np

a = np.array([1, 2, 3])
b = np.array([2, 3, 4])

np.concatenate((a, b))
# array([1, 2, 3, 2, 3, 4])


## 4.17.2. 2-dimensional Array

import numpy as np

a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6], [7, 8]])

np.concatenate((a, b))
# array([[1, 2],
#        [3, 4],
#        [5, 6],
#        [7, 8]])

np.concatenate((a, b), axis=0)
# array([[1, 2],
#        [3, 4],
#        [5, 6],
#        [7, 8]])

np.concatenate((a, b), axis=1)
# array([[1, 2, 5, 6],
#        [3, 4, 7, 8]])


## 4.17.3. Assignments

### 4.17.3.1. Array Concatenation

• Complexity level: easy

• Lines of code to write: 5 lines

• Estimated time of completion: 5 min

English
1. Given are one-dimensional: a: ndarray, b: ndarray (see below)

2. Concatenate them

3. Represent the result as ndarray: two rows and three columns

Polish
1. Dane są jednowymiarowe: a: ndarray, b: ndarray (patrz sekcja input)

2. Połącz je ze sobą

3. Przedstaw wynik jako ndarray: dwa wiersze na trzy kolumny

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

Output
array([[1, 2, 3],
[4, 5, 6]])