Instagram
youtube
Facebook
Twitter

Concatenate Two NumPy Arrays Vertically

A Concatenate Two NumPy Arrays Vertically?

Code Explanation:
Library Import: NumPy is imported for array operations.
Array Creation: Two 2D arrays are created with equal column count.
Vertical Concatenation: np.vstack((a, b)) stacks arrays on top of each other (row-wise).
Result Formation: Resulting array has shape (4, 2) after stacking.
Display Output: Prints the vertically concatenated array.

 

Program:

import numpy as np

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

b = np.array([[5, 6], [7, 8]])

result = np.vstack((a, b))

print(result)