2/18/2023

How to Vertically Stack Multiple Arrays Using numpy.vstack in Python

 refer to code:


.

import numpy as np

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

# Create a list of arrays
array_list = [a, b, c]

# Vertically stack all arrays in the list
result = np.empty((0, a.shape[0]))
for arr in array_list:
result = np.vstack((result, arr))

# Print the vertically stacked array
print(result)

..



Thank you.

๐Ÿ™‡๐Ÿป‍♂️

www.marearts.com

No comments:

Post a Comment