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
This function makes most sense ... concatenate, stack and block provide more general stacking and concatenation operations. np.row_stack is an alias for vstack....
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).
03:34
NumPy Stack Tutorial: Master np.stack() for Array Stacking | Python ...
Stacking and Splitting Numpy Arrays - Numpy Tutorial for Beginners ...
04:33
How to Stack two Arrays in NumPy | Python NumPy Tutorial - YouTube
04:11
Numpy Tutorial - 14 || Stacking in Numpy | STACK | HSTACK | VSTACK ...
NumPy
numpy.org › doc › 1.21 › reference › generated › numpy.row_stack.html
numpy.row_stack — NumPy v1.21 Manual
June 22, 2021 - Stack 1-D arrays as columns into a 2-D array. ... Split an array into multiple sub-arrays 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.
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.
NumPy
numpy.org › doc › 1.23 › reference › generated › numpy.row_stack.html
numpy.row_stack — NumPy v1.23 Manual
Stack 1-D arrays as columns into a 2-D array. ... Split an array into multiple sub-arrays 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 1-D arrays as columns into a 2-D array. ... Split an array into multiple sub-arrays vertically (row-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.
GeeksforGeeks
geeksforgeeks.org › python › numpy-ma-row_stack-in-python
numpy.ma.row_stack() in Python - GeeksforGeeks
July 16, 2018 - Row-wise stacked arrays Code #1: Explaining row_stack() Python3 1== # importing libraries import numpy as np # row_stacking array a = np.array([1, 2, 3]) arr = np.ma.row_stack (a) print ("arr : \n", arr) # row_stacking array b = np.array([[1], [2], [3]]) arr1 = np.ma.row_stack (b) print ("\narr1 : \n", arr1) Output : arr : [[1] [2] [3]] arr1 : [[1] [2] [3]] Code #2: Error generated with row_stack() Python3 1== # importing libraries import numpy as np # row_stacking array b = np.array([[1, 1], [2], [3]]) arr1 = np.ma.row_stack (b) print ("\narr1 : \n", arr1) Output : ValueError: all the input array dimensions except for the concatenation axis must match exactly.
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).
GeeksforGeeks
geeksforgeeks.org › python › numpy-stack-in-python
numpy.stack() in Python - GeeksforGeeks
December 13, 2025 - Python · import numpy as np x ... [ 6 12]]] Explanation: axis=0: stacks arrays as two “layers” of a 3D array. axis=1: stacks row-wise....
NumPy
numpy.org › doc › 1.13 › reference › generated › numpy.ma.row_stack.html
numpy.ma.row_stack — NumPy v1.13 Manual
Stack arrays in sequence vertically (row wise).
w3resource
w3resource.com › python-exercises › numpy › python-numpy-exercise-130.php
Python NumPy: Stack 1-D arrays as row wise - w3resource
August 29, 2025 - # Importing the NumPy library and aliasing it as 'np' import numpy as np # Printing a message indicating the original arrays will be displayed print("\nOriginal arrays:") # Creating a NumPy array 'x' with elements 1, 2, and 3 x = np.array((1, 2, 3)) # Creating another NumPy array 'y' with elements 2, 3, and 4 y = np.array((2, 3, 4)) # Printing a message for Array-1 and displaying the contents of array 'x' print("Array-1") print(x) # Printing a message for Array-2 and displaying the contents of array 'y' print("Array-2") print(y) # Stacking Array-1 'x' and Array-2 'y' as rows using np.row_stack() new_array = np.row_stack((x, y)) # Printing a message indicating the stacking of 1-D arrays as rows and displaying the resulting new array print("\nStack 1-D arrays as rows wise:") print(new_array)
Sling Academy
slingacademy.com › article › using-numpy-row_stack-function-4-examples
Using numpy.row_stack() function (4 examples) - Sling Academy
February 29, 2024 - It is equivalent to numpy.vstack() but specifically designed for row-wise stacking, thus making array concatenation intuitive.
NumPy
numpy.org › doc › stable › reference › generated › numpy.vstack.html
numpy.vstack — NumPy v2.5 Manual
Stack arrays in sequence vertically (row wise).
Top answer 1 of 2
1
You should not vstack while iterating, as it will artificially increase memory usage, as explained in this similar question but related to pandas.
Secondly, assuming fn(i) returns a new array that you want to append to A, then that line should be A = np.vstack((A, fn(i))
Considering all this, a better option would be to create and collect all your arrays into a list that you can later stack.
A = np.zeros((1, 14), dtype=float)
arrays = [A] + [fn(i) for i in arr] # assuming `arr` is an iterable
A = np.vstack(tuple(arrays))
You can read more in the numpy.vstack docs
2 of 2
0
You must add A on vstack:
A = np.zeros((1,14),dtype = float)
for i in arr:
A = np.vstack([A,fn(i)])# function returns array
Imperial College London
python.pages.doc.ic.ac.uk › lessons › numpy › 05-manipulation › 01-stack.html
Introduction to NumPy and Matplotlib > Array stacking | Python Programming | Department of Computing | Imperial College London
np.vstack(tuple): same as np.stack(tuple, axis=0) [Vertical stack]