Let’s say we have two or more NumPy arrays. We can combine these NumPy arrays vertically using the vstack() function from the numpy module. For example, we can use the following Python code to combine three NumPy arrays vertically.
import numpy A = numpy.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) B = numpy.array([10, 11, 12]) C = numpy.array([13, 14, 15]) D = numpy.vstack((A, B, C)) print("A: \n", A) print("B: \n", B) print("C: \n", C) print("D: \n", D)
Here, A, B, and C are three NumPy arrays. We are combining these three arrays using the vstack() function. Please note that the three arrays should have the same number of columns. The output of the given program will be:
A: [[1 2 3] [4 5 6] [7 8 9]] B: [10 11 12] C: [13 14 15] D: [[ 1 2 3] [ 4 5 6] [ 7 8 9] [10 11 12] [13 14 15]]
0 Comments