Signature
np.concatenate((a1, a2, ...), axis=0)What it does
np.concatenate stacks arrays that share every dimension except the chosen axis. Use it to combine feature blocks or append train and test predictions, and use np.vstack or np.hstack when you want the common shortcut.
Parameters
arrayssequence of ndarray- Arrays with matching shapes except along axis.
axisint, optionaloptional- Axis along which to join; default zero.
Returns
ndarray
Example
pythonnp.concatenate example
import numpy as np
age = np.array([[21], [34]])
income = np.array([[40.0], [55.0]])
print(np.concatenate([age, income], axis=1))Output
[[21. 40.] [34. 55.]]
Watch out for
- All other dimensions must match exactly or NumPy raises an error.
- Use np.column_stack for one-dimensional features that need a new axis.