This is called the "shape" in NumPy, and can be requested via the .shape attribute:

>>> a = zeros((2, 5))
>>> a.shape
(2, 5)

If you prefer a function, you could also use numpy.shape(a).

Answer from Sven Marnach on Stack Overflow
🌐
W3Schools
w3schools.com › python › gloss_python_array_length.asp
Python Array Length
Python Examples Python Compiler ... Q&A Python Bootcamp Python Certificate Python Training ... Use the len() method to return the length of an array (the number of elements in an array)....
Discussions

Creating an array who size and values depend on another array's values being put through a function
Since you mention arrays and arange, I presume you're using Numpy. The way to create one array by applying a function to each element from another array is by using vectorize . More on reddit.com
🌐 r/learnpython
6
18
May 21, 2022
Array length
It's ordered that way because that's the nature of a linked list. Usually, each element of a linked list consists of more than just the pointer to the next element in the list. You'll usually see linked lists used when new elements might be picked up or dropped from a list at any time, there is a need to be able to traverse the list, insertion or deletion is "expensive" (e.g., time-consuming), and the items being stored don't need to be stored in order in one big chunk of memory. It's just faster to include a pointer to the next element as part of the structure than to shuffle everything around whenever an insertion or deletion is needed. I suspect that this linked list consists of nothing but that pointer so that you can learn the nature of linked lists without being distracted by any additional overhead in each element in the list that you don't need to consider. Did that answer your question, or do you still have questions? More on reddit.com
🌐 r/learnpython
4
1
November 16, 2022
Why is getting the length of an array O(1) and not O(n)?
Most implementations store the length of an array in the object itself. Whenever you insert/remove it gets updated. Thus you're not iterating to get the length you're just getting a value. More on reddit.com
🌐 r/learnprogramming
45
11
November 7, 2022
What's the Python equivalent to this pseudo code for Array doubling in Data Structures?
Python is a high level programming language. While it’s possible to use libraries to get something resembling a C-style array, the Python programming language provides the list data-type which is an abstraction over an array that allows you to put arbitrary objects in it (it’s not restricted to a single type), and expand and reduce it dynamically (it handles memory allocation and de-allocation under the hood). The techniques you’re learning about at the moment are useful for understanding how programming works at a low level, but the whole point of a language like Python is that most of those techniques have been implemented for you (generally in quite optimised forms) in data structures that are easier and more pleasant to use while still being reasonably performant. Array doubling is useful because it provides amortised-constant runtime and linear memory usage when you’re wanting to expand a fixed-size array in individual steps, but that’s also what the append method does in Python’s list type. Of course for learning purposes you can just pretend that method doesn’t exist and implement its equivalent with your own code, it’s just good to be aware that when you’re programming in Python that kind of Han handling will generally be handled for you, and you’ll be operating at a more abstract level where you instead focus more on the actual ideas you’re trying to implement. Note that the understanding you’re gaining is valuable though. If you end up working with numerics (e.g. for data analysis or signal processing) then Python’s lists can be inefficient, in which case you’ll likely end up using arrays from the numpy library or DataFrames from the pandas or polars libraries. In those cases the expectation is to know how much data you have in advance, so appending is a linear-time operation that copies all the data to a slightly larger array every time, and is not recommended. More on reddit.com
🌐 r/learnpython
10
1
August 10, 2023
🌐
Flexiple
flexiple.com › python › length-of-array-python
Python Array Length - How to Calculate the Length of an Array in Python - Flexiple - Flexiple
Python array length can be determined using the len() method. This method counts the number of elements in an array, providing the total length. It is a direct way to measure the size of an array without needing to iterate through each element.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-array-length
Python Array length - GeeksforGeeks
July 23, 2025 - Finding the length of an array in Python means determining how many elements are present in the array. For example, given an array like [1, 2, 3, 4, 5], you might want to calculate the length, which is 5.
🌐
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 - You can get the size, i.e., the total number of elements, of a NumPy array with the size attribute. ... print(a_1d.size) # 3 print(type(a_1d.size)) # <class 'int'> print(a_2d.size) # 12 print(a_3d.size) # 24 ... len() is a built-in Python function ...
🌐
Python
docs.python.org › 3 › library › array.html
array — Efficient arrays of numeric values
This change doesn’t affect its behavior because Py_UNICODE is alias of wchar_t since Python 3.3. Deprecated since version 3.3, will be removed in version 3.16: Please migrate to 'w' typecode. Added in version 3.13. ... The ctypes and struct modules, as well as third-party modules like numpy, use similar – but slightly different – type codes. The actual representation of values is determined by the machine architecture (strictly speaking, by the C implementation). The actual size can be accessed through the array.itemsize attribute.
🌐
IONOS
ionos.com › digital guide › websites › web development › python array length
How to find out the length of a Python array
July 11, 2023 - Unlike with len, when you use size, you can also find out the number of elements in a mul­ti­di­men­sion­al array. To give you a better idea of how to use size, we’ll give you a code example. First, we’ll create the same array as in the example above, which contains the numbers 0 to 5 and saves the variable l as length.
Find elsewhere
🌐
Codedamn
codedamn.com › news › python
Python Array Size: How to Determine the Length
July 4, 2023 - The length of an array is the number ... In Python, the size of an array can be determined using the itemsize property, which returns the length in bytes of one array item....
🌐
Replit
replit.com › home › discover › how to find the length of an array in python
How to find the length of an array in Python | Replit
February 12, 2026 - numbers = [1, 2, 3, 4, 5] length = len(numbers) print(f"The length of the array is: {length}")--OUTPUT--The length of the array is: 5 · In this example, the len() function is called with the numbers list as its argument.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.ndarray.size.html
numpy.ndarray.size — NumPy v2.4 Manual
Equal to np.prod(a.shape), i.e., the product of the array’s dimensions. ... a.size returns a standard arbitrary precision Python integer.
🌐
Leapcell
leapcell.io › blog › understanding-array-length-in-python
Understanding Array Length in Python | Leapcell
July 25, 2025 - Here, len(np_array) returns the size of the first dimension (i.e., the number of rows), while .size gives the total number of elements in the entire array. The .shape attribute provides the dimensions of the array. Understanding how to determine the length of an array in Python depends on the type of data structure you're working with.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ndarray.size.html
numpy.ndarray.size — NumPy v2.1 Manual
Equal to np.prod(a.shape), i.e., the product of the array’s dimensions. ... a.size returns a standard arbitrary precision Python integer.
🌐
Scaler
scaler.com › home › topics › length of array in python
Length of array in Python - Scaler Topics
May 25, 2022 - We can use Python's len() function to find the length of an array.
🌐
CodeGym
codegym.cc › java blog › learning python › length of an array in python
Length of an Array in Python
November 7, 2024 - The simplest way to find the length of an array (or list) in Python is by using the len() function. This function is a built-in feature in Python and works on various data structures including lists, strings, and dictionaries.
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-size-function-python
Numpy size() function | Python - GeeksforGeeks
July 12, 2025 - Therefore np.size(arr, 0) will returns the number of rows and np.size(arr, 1) returns the number of columns. ... import numpy as np arr = np.array([[1, 2, 3, 4], [5, 6, 7, 8]]) print(np.size(arr, 0)) print(np.size(arr, 1))
🌐
iO Flood
ioflood.com › blog › get-length-of-array-in-python-guide-and-examples
Get Length of Array in Python: Guide and Examples
March 12, 2024 - The simplest way to determine the length of an array in Python is by using the built-in len() function. Simply pass the array as an argument to the function like so: length = len(array).
🌐
AI Planet
aiplanet.com › learn › introduction-to-numpy › attributes-of-an-array-and-creating-basic-array › 89 › shape-size-and-data-type-of-an-array
Shape, Size and Data Type of an Array | AI Planet (formerly DPhi)
You can check the number of dimensions of a NumPy array using the ‘.ndim’ attribute. The array ‘arr’ is 2 dimensional (i.e., the array has two axes). Everything in Python is an object.
🌐
Udacity
udacity.com › blog › 2021 › 10 › how-to-calculate-the-length-of-an-array-in-python.html
How to calculate the length of an array in Python? | Udacity
October 20, 2021 - NumPy is unique in allowing you to capture multi-dimensional arrays. Calling size() on a multi-dimensional array will print out the length of each dimension.
🌐
Java2Blog
java2blog.com › home › python › python array › python array size: get size of array in python
Python array size: get size of array in Python - Java2Blog
December 17, 2021 - In this article, we discussed several ways to get the size of array in Python. The most simple method is using the len() function, but it has its drawbacks and does not work with multidimensional arrays.
🌐
AskPython
askpython.com › home › how to find the array length in python
How to Find the Array Length in Python - AskPython
April 3, 2023 - Python len() method is used to find the length of an array. As we all know, python does not support or provide us with the array data structure in a direct