How to use the np.vstack function in Python?
The np.vstack function is used to vertically stack arrays. It stacks the input arrays together along the vertical direction, returning a new array.
Here is how to use it:
import numpy as np
# 创建两个数组
arr1 = np.array([[1, 2, 3],
[4, 5, 6]])
arr2 = np.array([[7, 8, 9],
[10, 11, 12]])
# 使用np.vstack函数垂直堆叠这两个数组
result = np.vstack((arr1, arr2))
print(result)
The result of the operation is:
[[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]]