Like this:

numrows = len(input)    # 3 rows in your example
numcols = len(input[0]) # 2 columns in your example

Assuming that all the sublists have the same length (that is, it's not a jagged array).

Answer from Óscar López on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-size-function-python
Numpy size() function | Python - GeeksforGeeks
July 12, 2025 - numpy.size() function in Python is used to count the number of elements in a NumPy array. You can use it to get the total count of all elements, or to count elements along a specific axis, such as rows or columns in a multidimensional array.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-using-2d-arrays-lists-the-right-way
Using 2D arrays/lists in Python - GeeksforGeeks
This article focuses on correct ... 1D and 2D lists in Python. A 1D list stores elements in a linear sequence. Although Python does not have a native 1D array type, lists serve the same purpose efficiently. 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". ... Explanation: [0] * N creates a list of size ...
Published   December 20, 2025
🌐
Drbeane
drbeane.github.io › python_dsci › pages › array_2d.html
2-Dimensional Arrays — Python for Data Science
We can replace one of the dimensions within reshape with a -1, in which case Numpy will infer the correct value from the size of the array. array3 = array1.reshape(4,-1) print('Shape =', array3.shape) print('Contents:') print(array3) Shape = (4, 3) Contents: [[ 1 2 3] [ 4 5 6] [ 7 8 9] [10 11 12]] In the following example, we reshape a 1D array into a 2D array with a single row, as well a 2D array with a single column.
🌐
CodeSignal
codesignal.com › learn › courses › multidimensional-arrays-and-their-traversal-in-python › lessons › exploring-the-dimensions-a-beginners-guide-to-multidimensional-arrays-in-python
A Beginner's Guide to Multidimensional Arrays in Python
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignalStart learning today! ... Continuing with the apartment-building analogy, suppose the task was to replace the old locker code (the second element in the first list) with a new one. Here's how we can achieve this: ... len(Array): It's like asking how many floors are there in our 'apartment building'.
🌐
NumPy
numpy.org › doc › stable › reference › arrays.ndarray.html
The N-dimensional array (ndarray) — NumPy v2.4 Manual
That is, an ndarray can be a “view” ... objects implementing the memoryview or array interfaces. ... Try it in your browser! A 2-dimensional array of size 2 x 3, composed of 4-byte integer elements:...
🌐
Bobby Hadz
bobbyhadz.com › blog › python-get-length-of-2d-array
How to get the length of a 2D Array in Python | bobbyhadz
Copied!import numpy as np my_2d_arr ... = rows * cols print(total_elements) # 👉️ 6 ... The size attribute returns the number of elements in the NumPy array....
🌐
sebhastian
sebhastian.com › python-2d-array-length
How to find the length of 2D array in Python | sebhastian
February 17, 2023 - To find the length of a 2D array, you need to find the total number of items stored in that array with the len() function.
Find elsewhere
🌐
Quora
quora.com › How-do-I-find-the-length-of-two-dimensional-arrays
How to find the length of two dimensional arrays - Quora
Answer: array= ([[1, 2], [3, 4], [5, 6]]) numrows = len(array) # 3 rows in your example numcols = len(array[0]) # 2 columns in your example print(numrows) print(numcols) reference: Find length of 2D array Python
🌐
Scaler
scaler.com › home › topics › 2d array in python
2D Array in Python | Python Two-Dimensional Array - Scaler Topics
October 10, 2025 - If an index exceeds the size, if the array is provided to this function, it returns the index out of range error. Such indices are known as out of bounds. It is further clarified by the examples below. Let's see some examples of how elements are accessed in a 2D array in python.
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: Get the dimensions, shape, and size of an array | note.nkmk.me
April 23, 2025 - The built-in len() function returns the size of the first dimension. ... Use the following one- to three-dimensional arrays as examples. import numpy as np a_1d = np.arange(3) print(a_1d) # [0 1 2] a_2d = np.arange(12).reshape((3, 4)) print(a_2d) ...
🌐
Python.org
discuss.python.org › python help
Need help with a two-dimensional array - Python Help - Discussions on Python.org
June 2, 2022 - Hello there! I’m an experienced coder who’s just getting into Python for the first time. I know several versions of BASIC, Pascal, C, C++, C#, PHP, MySQL… and so on. Here’s what I have: 1 2 3 4 5 6 7 8 A X X X X X X X X B X X X X X T X X C X X X X X X X X D X X X X X X X X E X X X X X X X X F X X X X X X X X G X X X X X X X X H X X X X X X X X This is a simple two-dimensional array.
🌐
Codedamn
codedamn.com › news › python
Python Array Size: How to Determine the Length
July 4, 2023 - However, when you use the len() function on a multidimensional array, it returns the length of the outermost array. import numpy as np a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) print(len(a)) In the above example, the output will be 3, ...
🌐
Runestone Academy
runestone.academy › ns › books › published › csawesome › Unit8-2DArray › a2dSummary.html
8.3. 2D Arrays Summary — CSAwesome v1
2d Array Initialization - You can also initialize (set) the values in the array when you first create it. In this case you don’t need to specify the size of the array, it will be determined from the number of values that you specify.
🌐
Javatpoint
javatpoint.com › python-2d-array
Python 2D array - Javatpoint
Python 2D array with python, tutorial, tkinter, button, overview, entry, checkbutton, canvas, frame, environment set-up, first python program, operators, etc.
🌐
NumPy
numpy.org › devdocs › user › absolute_beginners.html
NumPy: the absolute basics for beginners — NumPy v2.5.dev0 Manual
You might hear of a 0-D (zero-dimensional) array referred to as a “scalar”, a 1-D (one-dimensional) array as a “vector”, a 2-D (two-dimensional) array as a “matrix”, or an N-D (N-dimensional, where “N” is typically an integer greater than 2) array as a “tensor”. For clarity, it is best to avoid the mathematical terms when referring to an array because the mathematical objects with these names behave differently than arrays (e.g. “matrix” multiplication is fundamentally different from “array” multiplication), and there are other objects in the scientific Python ecosystem that have these names (e.g. the fundamental data structure of PyTorch is the “tensor”). This section covers the ndim, shape, size, and dtype attributes of an array.
🌐
Reddit
reddit.com › r/learnprogramming › why are 2d arrays in python so stupid?
r/learnprogramming on Reddit: Why are 2D arrays in Python so stupid?
September 5, 2019 -

Non-shitty languages:
int[] myArray = new int[5][5]

Python:
myArray = [[0]*5]*5

Next:
myArray[1][0] = 1
print(myArray[0][0])

Non-shitty languages:
0

Python:
1

Top answer
1 of 4
5
Because they aren't arrays, and aren't designed to be pre-allocated like that. Generally, if you need matrices use Numpy.
2 of 4
4
Just because it doesn't do what you expect doesn't mean it's stupid. Stock Python doesn't really do the kind of arrays you're talking about at all, and that was a design decision. In strongly typed languages, you often have to define the size of the array before using it. You need the type so you know how much memory one element takes, then you also need to know the dimensions, so the language knows how much space to allocate. This is powerful but a bit inflexible. Python tuples act a bit like a traditional array, because they are immutable. Once you've defined them, you cannot change the size or values. You'll never make an empty tuple, because a tuple's values can't be changed. This has certain advantages, but isn't super flexible. A python list, on the other hand, is ridiculously flexible. It can contain any number of elements. Each of these elements can be any type, including another list. They don't all have to be the same type or the same length. You can change any element at any time. There's no need to predefine the size of an array, so it's not surprising that such a mechanism doesn't exist. Of course, there's plenty of ways to build an array with preset values if you really want to: HEIGHT = 3 WIDTH = 5 a = [] for i in range(HEIGHT): a.append([0]*WIDTH) There's other ways to do this that take up a lot less space, but I prefer clarity over brevity when I'm programming in Python. Note that the syntax you describe as Python's way to build a 2D array doesn't do anything in my console, and I've never seen it before. This is far more flexible and powerful than the array types of a language like Java or C++. You don't create an array of a given size in Python because you don't need to. You can always adapt a list to do whatever you want. (BTW, Java and C++ have containers that act something like Python lists, too, but they aren't usually shown to beginners.) Note that if you want to make a true 2D array, you can always use the widely available numpy module to build a matrix. You then not only have an array that acts like you're expecting, you have access to plenty of matrix operations that traditional languages don't give you. TL;DR: Python doesn't act like some language you already know. That doesn't make it bad.
🌐
Reddit
reddit.com › r/learnpython › multidimensional arrays?
r/learnpython on Reddit: Multidimensional arrays?
September 15, 2023 -

Hello!

I have 5 sets, each set contains a number of elements of variable length (eg. set 1 has 100 elements, set 2 has 150 and so on)

Is it possible to store these sets in a single structure?

For example, if I want to print the 35th elements of the 3rd set, I could call it simply by saying something like MyContainer[setN][elementN]

I was trying to use a 2D array but I can't initialize its shape, since each set has a variable number of elements.

Can anybody point me to the right direction / best practice?

Thank you