You can get the same with:
import numpy as np
a = np.arange(7, 13).reshape(2, 3)
b = np.arange(1, 7).reshape(2, 3)
z = np.stack((a, b), axis=1)
print(z)
# [[[ 7 8 9]
# [ 1 2 3]]
#
# [[10 11 12]
# [ 4 5 6]]]
Answer from javidcf on Stack OverflowNumPy
numpy.org › doc › 1.25 › reference › generated › numpy.row_stack.html
numpy.row_stack — NumPy v1.25 Manual
Stack arrays in sequence horizontally (column wise).
Educative
educative.io › answers › what-is-the-numpyrowstack-function-in-numpy
What is the numpy.row_stack() function in NumPy?
The row_stack() function in NumPy is used to stack or arrange arrays in sequence vertically (row-wise).
TutorialsPoint
tutorialspoint.com › numpy › numpy_row_stack_function.htm
Numpy row_stack() Function
The numpy.row_stack() function stacks 1D arrays into rows of a 2D array, resulting in an array with shape (m, n), where m is the number of arrays and n is the length of the arrays.
NumPy
numpy.org › doc › 1.21 › reference › generated › numpy.row_stack.html
numpy.row_stack — NumPy v1.21 Manual
June 22, 2021 - Stack arrays in sequence vertically (row wise).
NumPy
numpy.org › doc › 1.25 › reference › generated › numpy.ma.row_stack.html
numpy.ma.row_stack — NumPy v1.25 Manual
Stack arrays in sequence horizontally (column wise).
Top answer 1 of 2
2
You can get the same with:
import numpy as np
a = np.arange(7, 13).reshape(2, 3)
b = np.arange(1, 7).reshape(2, 3)
z = np.stack((a, b), axis=1)
print(z)
# [[[ 7 8 9]
# [ 1 2 3]]
#
# [[10 11 12]
# [ 4 5 6]]]
2 of 2
0
You can use the numpy.row_stack method as follows:
a = np.arange(7, 13).reshape(2, 3)
b = np.arange(1, 7).reshape(2, 3)
x = np.row_stack((a[0],b[0]))
y = np.row_stack((a[1],b[1]))
z = np.row_stack([x, y])
Cheers.
NumPy
numpy.org › doc › 1.26 › reference › generated › numpy.ma.row_stack.html
numpy.ma.row_stack — NumPy v1.26 Manual
Stack arrays in sequence horizontally (column wise).
SciPy
docs.scipy.org › doc › numpy-1.10.0 › reference › generated › numpy.ma.row_stack.html
numpy.ma.row_stack — NumPy v1.10 Manual
Stack arrays in sequence vertically (row wise).
NumPy
numpy.org › doc › 1.23 › reference › generated › numpy.row_stack.html
numpy.row_stack — NumPy v1.23 Manual
Stack arrays in sequence vertically (row wise).
NumPy
numpy.org › doc › 1.20 › › reference › generated › numpy.row_stack.html
numpy.row_stack — NumPy v1.20 Manual
January 31, 2021 - Stack arrays in sequence vertically (row wise).
SciPy
docs.scipy.org › doc › numpy-1.13.0 › reference › generated › numpy.ma.row_stack.html
numpy.ma.row_stack — NumPy v1.13 Manual
Stack arrays in sequence vertically (row wise). Take a sequence of arrays and stack them vertically to make a single array. Rebuild arrays divided by vsplit. This function continues to be supported for backward compatibility, but you should prefer np.concatenate or np.stack.
Sling Academy
slingacademy.com › article › using-numpy-row_stack-function-4-examples
Using numpy.row_stack() function (4 examples) - Sling Academy
February 29, 2024 - numpy.row_stack(tup) Parameters: tup: sequence of array_like. The arrays must have the same shape along all but the first axis. 1-D arrays must have the same length. Returns: stacked: ndarray. The array formed by stacking the given arrays, will be at least 2-D. To begin, let’s look at a simple use case where we stack two one-dimensional arrays. import numpy as np a = np.array([1, 2, 3]) b = np.array([4, 5, 6]) result = np.row_stack((a, b)) print(result) This code yields the following output: [[1 2 3] [4 5 6]] This example demonstrates the straightforward application of numpy.row_stack() for combining two arrays vertically.
NumPy
numpy.org › doc › 1.18 › reference › generated › numpy.ma.row_stack.html
numpy.ma.row_stack — NumPy v1.18 Manual
May 24, 2020 - Stack arrays in sequence vertically (row wise).
SciPy
docs.scipy.org › doc › numpy-1.15.1 › reference › generated › numpy.ma.row_stack.html
numpy.ma.row_stack — NumPy v1.15 Manual
Stack arrays in sequence vertically (row wise).
SciPy
docs.scipy.org › doc › numpy-1.14.0 › reference › generated › numpy.ma.row_stack.html
numpy.ma.row_stack — NumPy v1.14 Manual
Stack arrays in sequence vertically (row wise).
GeeksforGeeks
geeksforgeeks.org › python › numpy-stack-in-python
numpy.stack() in Python - GeeksforGeeks
December 13, 2025 - import numpy as np a = np.array([1, 2, 3]) b = np.array([4, 5, 6]) print(np.stack((a, b), axis=0)) print(np.stack((a, b), axis=1)) print(np.stack((a, b), axis=-1)) Output · [[1 2 3] [4 5 6]] [[1 4] [2 5] [3 6]] [[1 4] [2 5] [3 6]] Explanation: axis=0: a and b become rows.