newarray = np.dstack(mylist)

should work. For example:

import numpy as np

# Here is a list of five 10x10 arrays:
x = [np.random.random((10,10)) for _ in range(5)]

y = np.dstack(x)
print(y.shape)
# (10, 10, 5)

# To get the shape to be Nx10x10, you could  use rollaxis:
y = np.rollaxis(y,-1)
print(y.shape)
# (5, 10, 10)

np.dstack returns a new array. Thus, using np.dstack requires as much additional memory as the input arrays. If you are tight on memory, an alternative to np.dstack which requires less memory is to allocate space for the final array first, and then pour the input arrays into it one at a time. For example, if you had 58 arrays of shape (159459, 2380), then you could use

y = np.empty((159459, 2380, 58))
for i in range(58):
    # instantiate the input arrays one at a time
    x = np.random.random((159459, 2380))
    # copy x into y
    y[..., i] = x
Answer from unutbu on Stack Overflow
Top answer
1 of 4
4

You can use numpy.dstack() to turn a list of 2D arrays into a 3D array:

https://docs.scipy.org/doc/numpy/reference/generated/numpy.dstack.html

2 of 4
1

If your array sizes are static as you mentioned, you can do the following

output_array = numpy.zeros((14,4,3), dtype=np.float32)
for i in range(14):
    mat = numpy.random.rand(4,3)
    output_array[i] = mat

you initialize your final array to the size you want and then loop over and assign your matrix (4,3) to the index of that respective loop counter.

The shape and your final matrix is

numpy.shape(output_array)

returns you

(14, 4, 3)

Output is

array([[[ 0.62507486,  0.3246161 ,  0.43934602],
    [ 0.14476213,  0.76139957,  0.92813474],
    [ 0.26556504,  0.02475475,  0.90740073],
    [ 0.08017973,  0.97526789,  0.2213122 ]],

   [[ 0.70042586,  0.8122381 ,  0.79289031],
    [ 0.0369414 ,  0.10780825,  0.77501732],
    [ 0.10386232,  0.86237574,  0.5829311 ],
    [ 0.1888348 ,  0.85105735,  0.31599012]],

   [[ 0.26350111,  0.8787083 ,  0.12869285],
    [ 0.25927794,  0.25701383,  0.81212741],
    [ 0.06661031,  0.53449911,  0.50212061],
    [ 0.40009728,  0.78002244,  0.81524432]],

   [[ 0.49921468,  0.82028496,  0.51261139],
    [ 0.62790054,  0.64566481,  0.02624587],
    [ 0.39364958,  0.99537313,  0.33225098],
    [ 0.88214922,  0.20252077,  0.78350848]],

   [[ 0.29032609,  0.95975012,  0.06733917],
    [ 0.24497923,  0.51818371,  0.93520784],
    [ 0.80267638,  0.88271469,  0.30779642],
    [ 0.57030594,  0.34175804,  0.52563131]],

   [[ 0.61039209,  0.57186425,  0.76554799],
    [ 0.55681604,  0.33107477,  0.05680386],
    [ 0.15465826,  0.13452645,  0.09498007],
    [ 0.29682869,  0.93196124,  0.94435322]],

   [[ 0.23904459,  0.94893754,  0.97033942],
    [ 0.89159942,  0.85306913,  0.02144577],
    [ 0.57696968,  0.82578647,  0.33358794],
    [ 0.81979036,  0.73351973,  0.027876  ]],

   [[ 0.6568135 ,  0.25458351,  0.10369358],
    [ 0.06151289,  0.00939822,  0.00798484],
    [ 0.92518032,  0.19057493,  0.84838325],
    [ 0.78189474,  0.15273546,  0.34607282]],

   [[ 0.46961641,  0.19778872,  0.1498462 ],
    [ 0.55704814,  0.96889585,  0.08894933],
    [ 0.48003736,  0.59383452,  0.42212519],
    [ 0.78752649,  0.07204869,  0.4215464 ]],

   [[ 0.6454156 ,  0.84189773,  0.10041234],
    [ 0.89345407,  0.60821944,  0.56667495],
    [ 0.62806529,  0.67642623,  0.4951494 ],
    [ 0.85371262,  0.13159418,  0.3402876 ]],

   [[ 0.39828625,  0.50659049,  0.34835485],
    [ 0.06839356,  0.74652916,  0.5722388 ],
    [ 0.20762053,  0.0692997 ,  0.02790474],
    [ 0.84786427,  0.98461425,  0.19105092]],

   [[ 0.36976317,  0.44268745,  0.23061621],
    [ 0.47827819,  0.43044546,  0.90150601],
    [ 0.2307732 ,  0.61590552,  0.82066673],
    [ 0.49611789,  0.4480612 ,  0.46685895]],

   [[ 0.40907925,  0.15996945,  0.05480348],
    [ 0.70230347,  0.00926704,  0.97775948],
    [ 0.19834276,  0.20127937,  0.44351548],
    [ 0.48512974,  0.07319999,  0.5580616 ]],

   [[ 0.35749629,  0.88443983,  0.55465496],
    [ 0.61600298,  0.08260803,  0.4010818 ],
    [ 0.40910226,  0.31984288,  0.50188118],
    [ 0.34836289,  0.14394118,  0.06841569]]], dtype=float32)

Hope that helps

Discussions

python - Building a 3D array from a number of 2D arrays with numpy - Stack Overflow
Everything fine so far, but how to add an additional 2D array to the 3D array, the following is not working: ... stack can work with a long list of 2d arrays like that. So if you have to do this repeatedly, append to the list and stack once. More on stackoverflow.com
🌐 stackoverflow.com
python - Convert 2D array to 3D numpy array - Stack Overflow
Dataframes are designed with 2d data in mind (# of sample vs. property is the typical case), so it makes little sense to stack them into a 3d numpy array; you would usually want either to keep them separate as a list/dict or stack them as a dataframe with an additional row for indexing. More on stackoverflow.com
🌐 stackoverflow.com
python - Converting list of 2-D arrays into a 3-D array, adding elements along "fast" axes - Stack Overflow
I have a list of 2d numpy arrays. More on stackoverflow.com
🌐 stackoverflow.com
python - Contruct 3d array in numpy from existing 2d array - Stack Overflow
During preparing data for NumPy calculate. I am curious about way to construct: myarray.shape => (2,18,18) from: d1.shape => (18,18) d2.shape => (18,18) I try to use NumPy command: hs... More on stackoverflow.com
🌐 stackoverflow.com
🌐
NumPy
numpy.org › doc › 1.13 › reference › generated › numpy.dstack.html
numpy.dstack — NumPy v1.13 Manual
June 10, 2017 - Takes a sequence of arrays and stack them along the third axis to make a single array. Rebuilds arrays divided by dsplit. This is a simple way to stack 2D arrays (images) into a single 3D array for processing.
Top answer
1 of 3
7

If you know all of your 2D arrays at the start, you can just stack more than two of them:

import numpy as np
a = np.zeros((3, 4))
b = np.zeros((3, 4))
c = np.stack((a, b, a))

If you already have one "stacked" array and want to add another array to it, you can use e.g. numpy.concatenate:

If the array you want to add is "flat", you would have to wrap it in a list to make the dimensions match. By default, the arrays are joined along the first dimension (same as if you were to specify axis=0 in the keyword arguments):

>>> c.shape
(2, 3, 4)
>>> np.array([a]).shape
(1, 3, 4)

c = np.concatenate((c, [a]))

If both arrays are already "stacked", this will also work:

c = np.concatenate((c, c))
2 of 3
3

You can add a new axis with None/np.newaxis at the start of the array to be appended : a[None,:,:] or simply a[None,...] or just a[None] and for stacking use np.vstack.

Here's a sample run to make things clear -

In [14]: c.shape
Out[14]: (2, 3, 4)

In [15]: d = np.vstack((c,a[None]))

In [16]: d.shape
Out[16]: (3, 3, 4)

In [17]: e = np.vstack((d,a[None]))

In [18]: e.shape
Out[18]: (4, 3, 4)

Workflow

So, the workflow would be :

1) To start off with 2D arrays, use new axes for the arrays :

c = np.vstack( (a[None],b[None]) )

2) For later appending steps, use new axis for the incoming 2D array and use np.vstack to stack with the existing 3D array -

d = np.vstack((c,a[None]))

Using np.concatenate for performance :

np.vstack under the hoods uses np.concatenate as a special case when we need to stack along the first axis. So, if we want to make use of np.concatenate maybe for performance reasons to avoid the additional function call overhead, we need to specify the axis of concatenation, which would be the first axis.

Thus, with np.concatenate -

In [23]: d = np.concatenate((c, a[None]), axis=0)

In [24]: d.shape
Out[24]: (3, 3, 4)

In [25]: e = np.concatenate((d, a[None]), axis=0)

In [26]: e.shape
Out[26]: (4, 3, 4)
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 44129160 › create-3d-array-from-multiple-2d-arrays
python - Create 3D array from multiple 2D arrays - Stack Overflow
3Darray_data1 =[] 3Darray_data2=[] xy_data1=[[0 for i in range(len(lons_data1))] for j in range(len(lats_data1))] xy_data2=[[0 for i in range(len(lons_data2))] for j in range(len(lats_data2))] # comparing the time steps for i in range(len(time_data1)): for j in range(len(time_data2)): if time_data1.year[i] == time_data2[j].year and time_data1[i].month==time_data2[j].month: # loop for data1 which writes the data into a 2D array for x in range(len(lats_data1)): for y in range(len(lons_data1)): xy_data1[x][y]=data1[j,0,x,y] # append to get an array of arrays xy_data1 = np.squeeze(np.asarray(xy_da
🌐
Python Guides
pythonguides.com › python-numpy-3d-array
3D Arrays In Python Using NumPy
May 16, 2025 - Think of it as a cube of data with ... in Python by using various methods with suitable examples. The most basic way to create a 3D array is using nested lists in Python:...
🌐
Python Like You Mean It
pythonlikeyoumeanit.com › Module3_IntroducingNumpy › AccessingDataAlongMultipleDimensions.html
Accessing Data Along Multiple Dimensions in an Array — Python Like You Mean It
Although NumPy does formally recognize the concept of dimensionality precisely in the way that it is discussed here, its documentation refers to an individual dimension of an array as an axis. Thus you will see “axes” (pronounced “aks-ēz”) used in place of “dimensions”; however, they mean the same thing. NumPy specifies the row-axis (students) of a 2D array as “axis-0” and the column-axis (exams) as axis-1.
🌐
GeeksforGeeks
geeksforgeeks.org › python › manipulating-multidimensional-arrays-in-python-numpy
Manipulating Multidimensional Arrays in Python NumPy - GeeksforGeeks
February 19, 2026 - 1. 2D Array from List of Lists: NumPy's np.array() function can create a 2D array from a list of lists, where each sub-list represents a row in the array. ... 2. 3D Array from Nested Lists: Similarly, a 3D array can be created from a nested ...
🌐
Medium
medium.com › @Dev_Frank › c-multidimensional-arrays-c8e0d8bd0ce0
C-MULTIDIMENSIONAL ARRAYS. A multi-dimensional array can be termed… | by Dev Frank | Medium
February 12, 2024 - You can create a 3D array in C using the following syntax, specifying the type of data, the array’s name, the number of 2D arrays (x), the number of rows in each 2D array (y), and the number of columns in each 2D array (z):
🌐
AskPython
askpython.com › python › array › multidimensional-arrays
Multidimensional Arrays in Python: A Complete Guide - AskPython
February 27, 2023 - In this article, the creation and implementation of multidimensional arrays (2D, 3D as well as 4D arrays) have been covered along with examples in Python Programming language. To understand and implement multi-dimensional arrays in Python, the NumPy package is used.
🌐
GeeksforGeeks
geeksforgeeks.org › numpy › numpy-reshape-2d-to-3d-array
Numpy Reshape 2D To 3D Array - GeeksforGeeks
July 23, 2025 - It can be visualized as a stack of 2D arrays. To reshape a 2D NumPy array into a 3D array, you can use the reshape() method.