Just doing d3 = array([d1,d2]) seems to work for me:

>>> from numpy import array
>>> # ... create d1 and d2 ...
>>> d1.shape
(18,18)
>>> d2.shape
(18,18)
>>> d3 = array([d1, d2])
>>> d3.shape
(2, 18, 18)
Answer from Daniel G on Stack Overflow
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)
🌐
Stack Overflow
stackoverflow.com › questions › 54960753 › create-a-3d-numpy-array-from-a-2d-numpy-array
python - create a 3d numpy array from a 2d numpy array - Stack Overflow
Until we have a clearer idea of what he's trying to do, your 3 loops are better than nothing. But when indexing a 3d array we prefer to use the arr3d[i, j, k] syntax. 2019-03-02T17:17:32.553Z+00:00 ... This may be what you're asking... Use numpy.reshape.
🌐
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.
🌐
IncludeHelp
includehelp.com › python › how-to-make-a-2d-numpy-array-a-3d-array.aspx
Python - How to make a 2d NumPy array a 3d array?
To make a 2d NumPy array a 3d array, we always use numpy.newaxis to add a new axis or to increase the dimension of the numpy array. If we are given a numpy array of shape (x,y), np.newaxis will add 1 more axis and the shape will become (x,y,1). ... Use ndarray.shape to get the shape.
🌐
Stack Overflow
stackoverflow.com › questions › 46181508 › creating-3d-array-from-2d-array-and-vector-in-python
numpy - Creating 3D array from 2D array and Vector in Python - Stack Overflow
I have a large 2D numpy array A of shape 20,000x500 and a vector numpy array B of shape 20,000. I want to concatenate B with each column of A to create a list of length 500 where each element of the list is as follows:
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › numpy › numpy-reshape-2d-to-3d-array
Numpy Reshape 2D To 3D Array - GeeksforGeeks
July 23, 2025 - We reshaped it into a 3D array ... that each 2D slice has a depth of 1. ... import numpy as np # Create a 2D array array_2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) # Reshape the 2D array into a 3D array ...
🌐
Stack Overflow
stackoverflow.com › questions › 67715874 › create-a-3d-numpy-array-with-3-2d-numpy-arrays-or-3-1d-numpy-array
python - Create a 3D numpy array with 3 2D numpy arrays or 3 1D numpy array - Stack Overflow
I have three numpy 2D arrays: A1 with the shape of (x * y) A2 with the shape of (x * z) A3 with the shape of (y * z) The values in the three arrays are either True or False. Now, I want to create ...
🌐
NumPy
numpy.org › devdocs › user › absolute_beginners.html
NumPy: the absolute basics for beginners — NumPy v2.6.dev0 Manual
Using np.newaxis will increase the dimensions of your array by one dimension when used once. This means that a 1D array will become a 2D array, a 2D array will become a 3D array, and so on.
🌐
Python Guides
pythonguides.com › python-numpy-3d-array
3D Arrays In Python Using NumPy
May 16, 2025 - When working with large 3D arrays, keep these tips in mind: Use NumPy operations instead of Python loops when possible · Consider data types to save memory (e.g., np.float32 instead of np.float64) For very large arrays, consider using sparse matrices or libraries like Dask for out-of-memory computation ... import numpy as np import time # Create a large 3D array large_array = np.random.rand(100, 100, 100) # Bad approach (using loops) start_time = time.time() result1 = np.zeros_like(large_array) for i in range(large_array.shape[0]): for j in range(large_array.shape[1]): for k in range(large_ar
🌐
Data science
hausetutorials.netlify.app › posts › 2019-12-20-numpy-reshape
Data science: Reshape and stack multi-dimensional arrays in Python numpy
October 20, 2019 - Because the three 3D arrays have been created by stacking two arrays along different dimensions, if we want to retrieve the original two arrays from these 3D arrays, we’ll have to subset along the correct dimension/axis.
🌐
NumPy
numpy.org › doc › stable › reference › arrays.ndarray.html
The N-dimensional array (ndarray) — NumPy v2.5 Manual
An ndarray is a (usually fixed-size) multidimensional container of items of the same type and size. The number of dimensions and items in an array is defined by its shape, which is a tuple of N non-negative integers that specify the sizes of each dimension. The type of items in the array is ...
🌐
Python Like You Mean It
pythonlikeyoumeanit.com › Module3_IntroducingNumpy › AccessingDataAlongMultipleDimensions.html
Accessing Data Along Multiple Dimensions in an Array — Python Like You Mean It
Keeping track of the meaning of an array’s various dimensions can quickly become unwieldy when working with real datasets. xarray is a Python library that provides functionality comparable to NumPy, but allows users provide explicit labels for an array’s dimensions; that is, you can name each dimension. Using an xarray to select Brad’s scores could look like grades.sel(student='Brad'), for instance. This is a valuable library to look into at your leisure. Let’s build up some intuition for arrays with a dimensionality higher than 2. The following code creates a 3-dimensional array: # a 3D array, shape-(2, 2, 2) >>> d3_array = np.array([[[0, 1], ...
🌐
W3Schools
w3schools.com › python › numpy › numpy_creating_arrays.asp
NumPy Creating Arrays
NumPy is used to work with arrays. The array object in NumPy is called ndarray.