I also don't recommend this, but you could use a numpy.chararray for this:

import numpy as np
arr = np.chararray((100, 12, 31, 24, 60, 60), itemsize=100)

arr[52, 7, 12, 12, 44, 54] = 'year 1950+52, 7th month, 12th day, 12th hour, 44th minute, 54th second'

I'm not exactly sure what your desired structure is, but the string I inserted into the array should explain the structure I proposed, and you can change it however you need. Note that itemsize limits how many characters you can put in at any index.

Again, with a caveat that this is not necessarily the most efficient thing in the world to do, but if you wish to store lists of ints and/or floats in that array (as per your comment), one way to do it would be to convert that list to strings, and then when retrieving it, re-transform back to a list:

data_to_insert = [1,2,3,4.5]
# store as string
arr[52, 7, 12, 12, 44, 54] = ','.join(map(str, data_to_insert))
# retrieve
arr[52, 7, 12, 12, 44, 54].decode('utf-8').split(',')

This should be pretty fast

Answer from sacuL on Stack Overflow
Top answer
1 of 2
2

I also don't recommend this, but you could use a numpy.chararray for this:

import numpy as np
arr = np.chararray((100, 12, 31, 24, 60, 60), itemsize=100)

arr[52, 7, 12, 12, 44, 54] = 'year 1950+52, 7th month, 12th day, 12th hour, 44th minute, 54th second'

I'm not exactly sure what your desired structure is, but the string I inserted into the array should explain the structure I proposed, and you can change it however you need. Note that itemsize limits how many characters you can put in at any index.

Again, with a caveat that this is not necessarily the most efficient thing in the world to do, but if you wish to store lists of ints and/or floats in that array (as per your comment), one way to do it would be to convert that list to strings, and then when retrieving it, re-transform back to a list:

data_to_insert = [1,2,3,4.5]
# store as string
arr[52, 7, 12, 12, 44, 54] = ','.join(map(str, data_to_insert))
# retrieve
arr[52, 7, 12, 12, 44, 54].decode('utf-8').split(',')

This should be pretty fast

2 of 2
2

Though i won't recommend it, A multi dimentional empty list can be created by using list comprehension:

> >>> a = 4 #Width of elements
> >>> b = 6 #Width of main list container
>>>>> c = 4
>>>>> d = 3
> >>> l = [[[[0 for k in range(d) ] for z in range(c)] for x in range(a)] for y in range(b)]
> >>> [[[[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]]], [[[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]]], [[[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]]], [[[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]]], [[[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]]], [[[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]]]]

Keep replacing 0 with list comprehensions to add more dimentions.

🌐
Quora
quora.com › How-do-you-create-an-empty-multidimensional-array-in-Python
How to create an empty multidimensional array in Python - Quora
Answer (1 of 5): You can’t - a multidimensional list (not array) in Python is a list of lists. if the top level list is empty then it isn’t multidimensional - it is an empty list. if the list on the next level down are empty then you have a list which is N by zero - hardly multi-dimensional.
Discussions

python - How can I create an empty 3d multidimensional array - Stack Overflow
As per my definition of 3D; the solution I mentioned earlier was a 3D list. It is a 4D list. OR, in other words you may say 3D list with value as empty lists 2016-12-19T16:28:04.99Z+00:00 More on stackoverflow.com
🌐 stackoverflow.com
python - how to create an empty 2 dimensional list based on another 2 dimensional list's length value? - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Ask questions, find answers and collaborate at work with Stack Overflow for Teams More on stackoverflow.com
🌐 stackoverflow.com
Python 2.7 creating a multidimensional list - Stack Overflow
Using numpy for multidimensionally arrays/lists could save you a ton of headache. ... I think your list comprehension versions were very close to working. You don't need to do any list multiplication (which doesn't work with empty lists anyway). More on stackoverflow.com
🌐 stackoverflow.com
How can i create multidimensional list in Python? - Stack Overflow
How can i create a multidimensional list while iterating through a 1d list based upon some condition. I am iterating over a 1d list and whenever i find a '\n' i should append the so created list w... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
gist.github.com › gonzacaminos › 16c830ffda05128a3481ea86ddd0024c
Create an empty multidimensional list in Python · GitHub
Create an empty multidimensional list in Python. GitHub Gist: instantly share code, notes, and snippets.
🌐
w3resource
w3resource.com › python-exercises › list › python-data-type-list-exercise-85.php
Python: Create a multidimensional list with zeros - w3resource
June 28, 2025 - Write a Python program to create a multidimensional list (lists of lists) with zeros. ... # Create an empty multidimensional list 'nums' nums = [] # Loop over a range of 3 times to create 3 sublists for i in range(3): # Append an empty sublist to 'nums' for each iteration nums.append([]) # Loop over a range of 2 times to fill each sublist with 2 zeros for j in range(2): # Append a zero to the current sublist for each iteration nums[i].append(0) # Print a message indicating the resulting multidimensional list print("Multidimensional list:") # Print the 'nums' list containing the structure of zeros print(nums)
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 160559 › empty-2d-array
python - Empty 2D Array [SOLVED] | DaniWeb
December 3, 2008 - If your data are sparse (many empty cells), a dictionary keyed by (row, col) avoids allocating full rows: from collections import defaultdict grid = defaultdict(dict) grid[r][c] = value # only store populated cells · For heavy numeric work, prefer NumPy arrays for performance and vectorization; initialize once you know dimensions: arr = numpy.zeros((rows, cols)) (NumPy zeros). More on the aliasing gotcha: Python FAQ: multidimensional lists.
🌐
Ubaldo Acosta Soto
ictdemy.com › python › basics › multidimensional-lists-in-python
Lesson 10 - Multidimensional lists in Python - ICTdemy.com
We have to keep in mind the outer list can be empty. We'll nest the loops in order so that the outer loop iterates over the rows and the inner one over the columns of the current row. After printing a row, we must break a line. Both loops must have a different control variable: {PYTHON} # declaration and adding columns cinema = [] for j in range(5): column = [] for i in range(5): column.append(0) cinema.append(column) # filling with data cinema[2][2] = 1 # center for i in range(1, 4): # fourth row cinema[i][3] = 1 for i in range(5): # the last row cinema[i][4] = 1 cols = len(cinema) rows = 0 if cols: rows = len(cinema[0]) for j in range(rows): for i in range(cols): print(cinema[i][j], end = "") print()
🌐
Snakify
snakify.org › two-dimensional lists (arrays)
Two-dimensional lists (arrays) - Learn Python 3 - Snakify
A possible way: you can create ... one-dimensional list of m elements: ... Another (but similar) way: create an empty list and then append a new element to it n times (this element should be a list of length m):...
🌐
Statistics Globe
statisticsglobe.com › home › python programming language for statistics & data science › create empty 2d list in python (2 examples)
Create Empty 2D List in Python (2 Examples) | Zero Elements
March 31, 2023 - How to make an empty 2D list in the Python programming language - Make empty 2D list using nested for loop - Python coding tutorial
Find elsewhere
🌐
Python Guides
pythonguides.com › create-an-empty-array-in-python
Ways to Initialize an Empty Python Array
January 12, 2026 - If I am processing a list of zip codes from the United States Census Bureau, I use the Python array module to save memory. import array # Creating an empty Python array of integers ('i' represents signed integers) # This is useful for memory-efficient storage of USA Zip Codes zip_codes = array.array('i') print(f"Empty Python Array: {zip_codes}") # Adding a Beverly Hills zip code zip_codes.append(90210) print(f"Updated Python Array: {zip_codes}")
🌐
Processing
py.processing.org › tutorials › 2dlists
Two-Dimensional Lists \ Tutorials
Python Mode for Processing extends the Processing Development Environment with the Python programming language.
🌐
Reddit
reddit.com › r/learnpython › multidimensional lists - creating, reading and updating
r/learnpython on Reddit: Multidimensional Lists - creating, reading and updating
March 7, 2022 -

New to python but not other higher level languages.

I’m having difficulty understanding how to use multidimensional lists in python.

I have a list if 256 objects. Each object has 6 variables. In other languages, I could read and update/change similar to

object[0] = [1,2,3,4,5,6]

…

object[255] = [1,2,3,4,5,6] Etc.

I understand in python this isn’t possible, so I’ll have to revert to something similar to

object = [[0], [1,2,3,4,5,6]]

…

object = [[255], [1,2,3,4,5,6]]

And reading will be similar to

var1 = object[0][3]

print(var1)

But I can’t get my head around it or find easy to,understand examples.

Does anyone have any quick and easy to digest resources that could help me understand this a bit better?

Thanks!

🌐
GeeksforGeeks
geeksforgeeks.org › python-using-2d-arrays-lists-the-right-way
Python | Using 2D arrays/lists the right way - GeeksforGeeks
Manually initializing and populating a list without using any advanced features or constructs in Python is known as creating a 1D list using "Naive Methods". ... Here we are multiplying the number of rows by the empty list and hence the entire list is created with every element zero.
Published: June 20, 2024
🌐
TutorialsPoint
tutorialspoint.com › article › how-do-i-create-a-multidimensional-list-in-python
How do I create a multidimensional list in Python?
September 16, 2022 - Multidimensional lists are created by nesting lists within lists. Use list[row][col] to access elements and append() to add new rows.
🌐
Reddit
reddit.com › r/learnpython › issue with empty slots in multidimensional array
r/learnpython on Reddit: Issue with empty slots in multidimensional array
September 8, 2020 -

Hey guys,

I was wondering what was the best way to handle this. Example code as follows:

myArray = [[1],[2],[3],[],[5]]

for item in myArray:

try:

print(item[0])

except:

item[0] = 0

print(item[0])

So, the idea is to create an array which have one element which is empty. When encountered, Python returns an error (wrong index).

So I want to find a way to assign a value (empty string or 0 depending on specific case) when this error is encountered. However, the sample code above returns the same error. It's as if given index is invalid completely. Is there any workaround for this one?

Edit:

Fairly sure same is true for one-dimensional array. And I guess list, not array. Sorry :D