axis : int, optionalThe axis along which the arrays will be joined. If axis is None, arrays are flattened before use. Default is 0.
- axis=0
It concatenates along the row axis.
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]])
- axis=1
It concatenates along the column axis.
np.concatenate((a, b), axis=1)
>>>
ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 2 and the array at index 1 has size 1
b.T
>>>
array([[5],
[6]])
np.concatenate((a, b.T), axis=1)
>>>
array([[1, 2, 5],
[3, 4, 6]])
- axis=None
np.concatenate((a, b), axis=None)
>>>
array([1, 2, 3, 4, 5, 6])
'Analyze Data > Python Libraries' 카테고리의 다른 글
numpy-ogrid VS mgrid (0) | 2023.11.17 |
---|---|
EasyDict (0) | 2023.10.18 |
numpy-identity (0) | 2023.06.02 |
numpy-linspace, interp (0) | 2023.05.30 |
numpy-np.c_[] VS np.r_[] (0) | 2023.05.25 |