shape is a property of both numpy ndarray's and matrices.

A.shape

will return a tuple (m, n), where m is the number of rows, and n is the number of columns.

In fact, the numpy matrix object is built on top of the ndarray object, one of numpy's two fundamental objects (along with a universal function object), so it inherits from ndarray

Answer from Kyle Heuton on Stack Overflow
🌐
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 - In this code, we first import the numpy module and create a numpy array. We then calculate the memory usage by multiplying the itemsize of the array by the length of the array.
🌐
Apache Spark
spark.apache.org › docs › latest › rdd-programming-guide.html
RDD Programming Guide - Spark 4.1.1 Documentation
Spark 4.1.1 works with Python 3.10+. It can use the standard CPython interpreter, so C libraries like NumPy can be used.
🌐
Cgohlke
cgohlke.com
Christoph Gohlke
NumPy is the primary array programming library for the Python language. It has an essential role in research analysis pipelines in fields as diverse as physics, chemistry, astronomy, geoscience, biology, psychology, materials science, engineering, finance and economics.
🌐
Oreate AI
oreateai.com › blog › beyond-the-line-understanding-the-difference-between-1d-and-2d-arrays › 41130d625489f502ef2fda5379c59c46
Beyond the Line: Understanding the Difference Between 1D and 2D Arrays - Oreate AI Blog
February 24, 2026 - The fundamental difference, then, boils down to dimensionality. A 1D array has one dimension – a length. A 2D array has two dimensions – a length and a width, or more commonly, rows and columns.
🌐
GitHub
github.com › karpathy › nanoGPT
GitHub - karpathy/nanoGPT: The simplest, fastest repository for training/finetuning medium-sized GPTs. · GitHub
December 29, 2022 - Not bad for ~3 minutes on a CPU, for a hint of the right character gestalt. If you're willing to wait longer, feel free to tune the hyperparameters, increase the size of the network, the context length (--block_size), the length of training, etc.
Starred by 55.7K users
Forked by 9.5K users
Languages   Python
🌐
scikit-learn
scikit-learn.org › stable › modules › generated › sklearn.model_selection.train_test_split.html
train_test_split — scikit-learn 1.8.0 documentation
>>> X_train, X_test, y_train, y_test = train_test_split( ... X, y, test_size=0.33, random_state=42) ... >>> X_train.head() sepal length (cm) sepal width (cm) petal length (cm) petal width (cm) 96 5.7 2.9 4.2 1.3 105 7.6 3.0 6.6 2.1 66 5.6 3.0 4.5 1.5 0 5.1 3.5 1.4 0.2 122 7.7 2.8 6.7 2.0 >>> y_train.head() 96 1 105 2 66 1 0 0 122 2 ...
Find elsewhere
🌐
Packt
packtpub.com › en-us › learning › how-to-tutorials › numpy-array-object
The NumPy array object
As you can see, the vector has five components with values ranging from 0 to 4. The shape property of the array is a tuple; in this instance, a tuple of 1 element, which holds the length in each dimension. Now that we know how to create a vector, we are set to create a multidimensional NumPy array.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ndarray.size.html
numpy.ndarray.size — NumPy v2.1 Manual
Number of elements in the array · Equal to np.prod(a.shape), i.e., the product of the array’s dimensions
🌐
Berkeley
pythonnumericalmethods.studentorg.berkeley.edu › notebooks › chapter02.07-Introducing_numpy_arrays.html
Introducing Numpy Arrays — Python Numerical Methods
In the 2nd part of this book, we will study the numerical methods by using Python. We will use array/matrix a lot later in the book. Therefore, here we are going to introduce the most common way to handle arrays in Python using the Numpy module.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › how to get numpy array length
How to Get NumPy Array Length - Spark By {Examples}
March 27, 2024 - You can find the length of a NumPy array using the built-in len() function in Python, which returns the number of elements in the first dimension of the array.
🌐
Klipper
klipper3d.org › G-Codes.html
G-Codes - Klipper documentation
(The stepper motor may move forwards or backwards two full rotations during this test.) After completing this test use the SAVE_CONFIG command to save the calibration data to the config file. In order to use this tool the Python "numpy" package must be installed (see the measuring resonance ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-size-function-python
Numpy size() function | Python - GeeksforGeeks
July 12, 2025 - 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))
🌐
Pythoninformer
pythoninformer.com › python-libraries › numpy › anatomy-of-array
PythonInformer - Anatomy of a numpy array
February 10, 2018 - It gets difficult to draw arrays with more than 3 dimensions, but numpy allows you to have as many dimensions as you want. The shape of an array specifies the length of the array in each dimension. It is usually represented as a tuple.
🌐
Liberian Geek
liberiangeek.net › home › how-to/tips › how to get/find length of an array in python?
How to Get/Find Length of an Array in Python? | Liberian Geek
December 27, 2023 - To get the array’s length, use the “len()” method, “length_hint()” method, “__len__()” method, “.size” or “.shape” attribute of NumPy library or “for” loop.
🌐
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 number of dimensions of a NumPy array as an integer using the ndim attribute.
🌐
Medium
medium.com › @whyamit101 › understanding-vector-length-in-numpy-c05264f58ef2
Understanding Vector Length in NumPy | by why amit | Medium
February 26, 2025 - Lengths of Vectors: [ 5. 2.23606798 13. ] ... And just like that, NumPy handles multiple vectors with ease.
🌐
Pint
pint.readthedocs.io › en › 0.24.2 › user › numpy.html
NumPy Support — pint 0.24.2 documentation
The magnitude of a Pint quantity can be of any numerical scalar type, and you are free to choose it according to your needs. For numerical applications requiring arrays, it is quite convenient to use NumPy ndarray (or ndarray-like types supporting NEP-18), and therefore these are the array ...