If the array is sparse (rare True values); you could use collections.defaultdict:

from collections import defaultdict

a = defaultdict(bool)
a[i,j,k,m] = True
Answer from jfs on Stack Overflow
🌐
EDUCBA
educba.com › home › software development › software development tutorials › python tutorial › 3d arrays in python
3d Arrays in Python | How to Create,Insert And Remove 3D Array In Python
April 23, 2024 - And the answer is we can go with the simple implementation of 3d arrays with the list. But for some complex structures, we have an easy way of doing it by including Numpy. It is not recommended which way to use it. It depends on the project and requirement of how you want to implement a particular functionality. Python has a set of libraries defines to ease the task.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Reddit
reddit.com › r/learnpython › help with matrices (without using numpy)
r/learnpython on Reddit: Help with matrices (without using numpy)
January 16, 2021 -

Hello,

I'm learning to code in Python and I'm stuck on a part of a question. I have googled a lot and tried to do it without success.

The user enters two matrices that are retained in the program as two-dimensional lists. The program checks whether the matrix sizes allow matrix multiplication and in that case performs the matrix multiplication. The result is saved in a new two-dimensional list.

I succeed with the part where users input the lists, but do not know how to proceed after that. Does anyone have any ideas on how to do this? I'm not allowed to use numpy on this assignment.

I would really appreciate some help.

🌐
YouTube
youtube.com › the python oracle
Good way to make a multi dimensional array without numpy - YouTube
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn--Music by Eric Matyashttps://www.soundimage.orgTrack title: Hypnotic...
Published   January 11, 2023
Views   94
🌐
w3resource
w3resource.com › python-exercises › list › python-data-type-list-exercise-13.php
Python: Generate a 3D array - w3resource
So, the resulting array is a 3D array of size 3x4x6, with every element initialized to the character '*'. Finally print() function prints the said array. ... Write a Python program to generate a 3D array where each element is its coordinate sum.
🌐
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 ...
Find elsewhere
🌐
Medium
medium.com › @girginlerheryerde › layer-by-layer-understanding-3d-arrays-in-python-a5709b7ef8d1
Layer by Layer: Understanding 3D Arrays in Python | by Ayşenas Girgin | Medium
March 17, 2025 - In this post, we’ll explore what 3D arrays are, why we use them, and how to work with them effectively in Python — all without getting buried in code.
Top answer
1 of 6
71

You have a truncated array representation. Let's look at a full example:

>>> a = np.zeros((2, 3, 4))
>>> a
array([[[ 0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.]],

       [[ 0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.],
        [ 0.,  0.,  0.,  0.]]])

Arrays in NumPy are printed as the word array followed by structure, similar to embedded Python lists. Let's create a similar list:

>>> l = [[[ 0.,  0.,  0.,  0.],
          [ 0.,  0.,  0.,  0.],
          [ 0.,  0.,  0.,  0.]],

          [[ 0.,  0.,  0.,  0.],
          [ 0.,  0.,  0.,  0.],
          [ 0.,  0.,  0.,  0.]]]

>>> l
[[[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]], 
 [[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]]]

The first level of this compound list l has exactly 2 elements, just as the first dimension of the array a (# of rows). Each of these elements is itself a list with 3 elements, which is equal to the second dimension of a (# of columns). Finally, the most nested lists have 4 elements each, same as the third dimension of a (depth/# of colors).

So you've got exactly the same structure (in terms of dimensions) as in Matlab, just printed in another way.

Some caveats:

  1. Matlab stores data column by column ("Fortran order"), while NumPy by default stores them row by row ("C order"). This doesn't affect indexing, but may affect performance. For example, in Matlab efficient loop will be over columns (e.g. for n = 1:10 a(:, n) end), while in NumPy it's preferable to iterate over rows (e.g. for n in range(10): a[n, :] -- note n in the first position, not the last).

  2. If you work with colored images in OpenCV, remember that:

    2.1. It stores images in BGR format and not RGB, like most Python libraries do.

    2.2. Most functions work on image coordinates (x, y), which are opposite to matrix coordinates (i, j).

2 of 6
27

No need to go in such deep technicalities, and get yourself blasted. Let me explain it in the most easiest way. We all have studied "Sets" during our school-age in Mathematics. Just consider 3D numpy array as the formation of "sets".

x = np.zeros((2,3,4)) 

Simply Means:

2 Sets, 3 Rows per Set, 4 Columns

Example:

Input

x = np.zeros((2,3,4))

Output

Set # 1 ---- [[[ 0.,  0.,  0.,  0.],  ---- Row 1
               [ 0.,  0.,  0.,  0.],  ---- Row 2
               [ 0.,  0.,  0.,  0.]], ---- Row 3 
    
Set # 2 ----  [[ 0.,  0.,  0.,  0.],  ---- Row 1
               [ 0.,  0.,  0.,  0.],  ---- Row 2
               [ 0.,  0.,  0.,  0.]]] ---- Row 3

Explanation: See? we have 2 Sets, 3 Rows per Set, and 4 Columns.

Note: Whenever you see a "Set of numbers" closed in double brackets from both ends. Consider it as a "set". And 3D and 3D+ arrays are always built on these "sets".

🌐
freeCodeCamp
forum.freecodecamp.org › python
Python arrays without numpy! - Python - The freeCodeCamp Forum
November 5, 2020 - Can someone help me regarding the subtraction and multiplication of two matrices which I created using arrays (without numpy) and I am doing it using object oriented by making class and functions. I had created 2 matrice…
🌐
Reddit
reddit.com › r/learnpython › declaring a 3d array (list?) in python
r/learnpython on Reddit: Declaring a 3D array (list?) in Python
November 8, 2013 -

Hello friends. I am trying to start to learn Python, but I am having some trouble getting past the early steps. I have a working knowledge of C and have figured out how to transfer most things over to the new syntax, but this one eludes me. I would like to declare a three dimensional array, which I believe may be called a list in Python, similar to this example in C:

int map[2][3][5] = {{
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0}},{

{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0}}}

Please note I may have gotten my bracketing slightly wrong here. I always get confused without a compiler to correct me, but you know what I'm going for - an expandable set of 2D arrays I can define when they are initialized.

My issue is finding documentation that allows me to declare and reference a variable in this way. I need the program to be able to hit specific tiles, such as map[1][2][0] vs. map[1][2][1], and all the information I've found regarding declarations for Python seem to lean towards not defining these borders and having these vaguely long lists that I'm not sure how to manage properly. I thought I might be missing something, possibly searching for the wrong words (Is it called a 3D list? Who knows!) or looking in the wrong areas. If this is an easy thing to look up, I'm sorry, I've tried over and over before posting and I just can't get it to come up with what I need. Any help would be greatly appreciated!

As a final note, this is one of the first things I need to figure out to teach myself Python, so it would be best to assume I have little knowledge of the terminology and syntax. All my programming before this was straight C, not even C++ really, so it is very foreign looking to me.

Top answer
1 of 5
5
First of all, you wouldn't get confused with your bracketing if you wrote it a little differently: int map[2][3][5] = { { {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0} }, { {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0} } } Anyway, you basically have two options: Option 1: list of lists of lists x, y, z = 2, 3, 5 map = [] for _ in range(x): sublist = [] for _ in range(y): subsublist = [0] * z sublist.append(subsublist) map.append(sublist) This can be written more compactly using nested list comprehensions: x, y, z = 2, 3, 5 map = [[[0 for c in range(z)] for b in range(y)] for a in range(x)] Doing it this way, your dimensions are fixed size (you'll get IndexError if you try to access invalid indices), but it is non-ideal because it is really a list of lists of lists. You'll have to be careful not to accidentally make multiple references to the same sublists, because that would probably lead to confusing unexpected results. Option 2: dictionary with (x, y, z) tuples as the keys x, y, z = 2, 3, 5 map = {(a, b, c): 0 for a in range(x) for b in range(y) for c in range(z)} # Now access items like map[(2, 3, 5)] # or even map[2, 3, 5] This is nice because the set-up is simpler. The downside is that there's no safeguard against adding new items with out-of-bounds indices. EDIT: Probably a good idea to call this something other than map, because map() is a built-in function that you may find yourself needing to use.
2 of 5
4
n-dimensional arrays in python can be represented as just lists of lists. Are you familiar with how to make a single list?
🌐
GeeksforGeeks
geeksforgeeks.org › python-creating-3d-list
Python - Creating a 3D List - GeeksforGeeks
December 11, 2024 - Scalar, 1 and 2 dimensional inputs are converted to 3-dimensional arrays, whilst higher-dimensional inputs are preserved. Input includes scalar, lists, lists of tuples, tuples, tuples of tuple ... Heatmaps are a great way to visualize a dataset, methods for visualizing the data are getting explored constantly and 3D heatmap is one of the ways to plot data. Let's learn how we can plot 3D data in python.
🌐
Quora
quora.com › How-can-you-create-an-array-3D-in-Python
How to create an array 3D in Python - Quora
Answer: In Python, you can create a 3D array using lists or, preferably, NumPy arrays. NumPy is a powerful library for numerical operations, and it provides convenient functions for working with multi-dimensional arrays. Here's how you can create a 3D array using NumPy:
🌐
Python Forum
python-forum.io › thread-1818.html
Creating 2D array without Numpy
I want to create a 2D array and assign one particular element. The second way below works. But the first way doesn't. I am curious to know why the first way does not work. Is there any way to create a zero 2D array without numpy and without loop? ...
🌐
Reddit
reddit.com › r/learnpython › creating an array without using numpy
r/learnpython on Reddit: Creating an array without using numpy
April 25, 2021 -

In my homework, numpy usage wasn't allowed but I realize that just now. I have to delete all the np.array() components and define an array without using them. I couldn't find a way.

import numpy as np
    
    def rotate_clockwise(x):
        return x[::-1].T
    
    
    def find(element, matrix):
        for i in range(len(matrix)):
            for j in range(len(matrix[i])):
                if matrix[i][j] == element:
                    return (i+1, j+1)
    N = int(input())
    S = int(input())
    
    arr = np.array(range(0,N*N))
    
    arr.shape = N,N
    for i in range(S):
        a,b,c = [int(x) for x in input().split()]
        arr[a - 1:a + c, b - 1:b + c] = rotate_clockwise(arr[a - 1:a + c, b - 1:b + c])
    
    
    M = int(input())
    items = np.array(range(0,M))
    for i in range(M):
        danscisayisi=int(input())
        items[i]=(danscisayisi)
    
    for i in range(0, len(items)):
        items[i] = int(items[i])
    noktalar = np.array(range(0,M))
    for i in range(M):
        coord=(find(items[i],arr))
        result = " ".join(str(x) for x in coord)
        print(result)