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).
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)....
Top answer 1 of 3
73
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).
2 of 3
14
Yes numpy has a size function, and shape and size are not quite the same.
Input
import numpy as np
data = [[1, 2, 3, 4], [5, 6, 7, 8]]
arrData = np.array(data)
print(data)
print(arrData.size)
print(arrData.shape)
Output
[[1, 2, 3, 4], [5, 6, 7, 8]]
8 # size
(2, 4) # shape
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
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
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
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
Videos
00:23
Python | Length Array - YouTube
03:34
python length of an array - YouTube
18:59
Understanding Python Numpy Dimensions, Shape, and Slice Operations ...
02:28
Python numpy Tutorial | How to identify the size of an array | ...
02:14
Check how many dimensions a Numpy array has in Python - YouTube
03:15
python array declaration with size - YouTube
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 multidimensional 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.
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.
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))
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.