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
Discussions

what's the difference between a numpy array with shape (x,) and (x, 1)?
import numpy as np arr = np.array([1, 2, 3, 4, 5]) print(arr.shape) # Output: (5,) arr = np.array([[1], [2], [3], [4], [5]]) print(arr.shape) # Output: (5, 1) arr = np.array([[1, 2, 3, 4, 5]]) print(arr.shape) # Output: (1, 5) More on reddit.com
🌐 r/learnpython
6
1
October 6, 2023
How can I create a truly empty numpy array which can be merged onto (by a recursive function)?
I can't say I fully followed your problem statement, but you can create an array with a total size of zero if any of the dimensions has size zero: a = np.empty((0, 3)) # Doesn't really matter if you use `empty`, `zeros` or `ones` here Zero-size arrays are the neutral element wrt. concatenation along their zero-size dimension (if that's what you mean by "merging"): b = np.random.uniform(size=(20, 3)) c = np.concatenate([a, b], 0) (c == b).all() # True More on reddit.com
🌐 r/learnpython
2
2
September 21, 2023
How do I replace alternating rows in an array with a specific number?
By "array", do you mean list? Or in your case a list of lists? Assume you have the following 4x4 list. L = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] One way to alternate rows is to check if the row index is divisible by 2. >>> for row_idx, row in enumerate(L): if row_idx % 2 == 1: # "odd" rows for col_idx, _ in enumerate(row): L[row][col_idx] = 2 >>> L [[0, 0, 0, 0], [2, 2, 2, 2], [0, 0, 0, 0], [2, 2, 2, 2]] Edit: based on your other comment, it appears that you have a 1-dimensional list where every 12th element signifies the switch to a new row, is that correct? More on reddit.com
🌐 r/learnpython
10
1
October 18, 2022
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
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-size-function-python
Numpy size() function | Python - GeeksforGeeks
July 12, 2025 - The numpy.size() function is a tool to understand how many elements exist in your array whether it's one-dimensional or multi-dimensional.
🌐
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 - In Python Numpy you can get array length/size using numpy.ndarray.size and numpy.ndarray.shape properties. The size property gets the total number of
🌐
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 - For a numpy.ndarray, len() returns the size of the first dimension, which is equivalent to shape[0]. It is also equal to size only for one-dimensional arrays.
🌐
CodeGym
codegym.cc › java blog › learning python › length of an array in python
Length of an Array in Python
November 7, 2024 - The length of an array refers to the number of elements it contains. You can use the built-in len() function to easily find the length of a list, numpy array, or array from the array module.
Find elsewhere
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.size.html
numpy.size — NumPy v2.2 Manual
number of elements in array · Examples · >>> import numpy as np >>> a = np.array([[1,2,3],[4,5,6]]) >>> np.size(a) 6 >>> np.size(a,1) 3 >>> np.size(a,0) 2 ·
🌐
NumPy
numpy.org › doc › stable › user › absolute_beginners.html
NumPy: the absolute basics for beginners — NumPy v2.5 Manual
shape is the new shape you want. You can specify an integer or a tuple of integers. If you specify an integer, the result will be an array of that length.
🌐
Leapcell
leapcell.io › blog › understanding-array-length-in-python
Understanding Array Length in Python | Leapcell
July 25, 2025 - To find the number of elements in a NumPy array, you can use either len() or the .size attribute:
🌐
Pierian Training
pieriantraining.com › home › python numpy tutorial: get length of array in python
Python NumPy Tutorial: Get Length of Array in Python - Pierian Training
April 27, 2023 - The easiest and most straightforward way to get the length of a NumPy array is by using the built-in Python function `len()`. This function returns the number of elements in an object, including the elements in a NumPy array.
🌐
NumPy
numpy.org › doc › 2.4 › reference › arrays.ndarray.html
The N-dimensional array (ndarray) — NumPy v2.4 Manual
An ndarray is a (usually fixed-size) multidimensional container of items of the same type and size. The number of dimensions and items in an array is defined by its shape, which is a tuple of N non-negative integers that specify the sizes of each dimension.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ma.size.html
numpy.ma.size — NumPy v2.1 Manual
number of elements in array · Examples · >>> import numpy as np >>> a = np.array([[1,2,3],[4,5,6]]) >>> np.size(a) 6 >>> np.size(a,1) 3 >>> np.size(a,0) 2 ·
🌐
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. For a Numpy array also, we can use the len() function to find the array's length in Python.
🌐
Python
docs.python.org › 3 › library › itertools.html
itertools — Functions creating iterators for efficient looping
The following functions all construct and return iterators. Some provide streams of infinite length, so they should only be accessed by functions or loops that truncate the stream.
🌐
Qwen
qwen.ai › blog
Qwen
Qwen offers comprehensive functionality spanning chatbot, image and video understanding, image generation, document processing, web search integration, tool utilization, and artifacts.
🌐
SciPy
docs.scipy.org › doc › scipy › reference › generated › scipy.ndimage.binary_erosion.html
binary_erosion — SciPy v1.18.0 Manual
See Support for the array API standard for more information. ... Try it in your browser! >>> from scipy import ndimage >>> import numpy as np >>> a = np.zeros((7,7), dtype=int) >>> a[1:6, 2:5] = 1 >>> a array([[0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) >>> ndimage.binary_erosion(a).astype(a.dtype) array([[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]]) >>> #Erosion removes objects smaller than the structure >>> ndimage.binary_erosion(a, structure=np.ones((5,5))).astype(a.dtype) array([[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]])
🌐
TutorialsPoint
tutorialspoint.com › article › find-the-size-of-numpy-array
Find the size of numpy Array
March 27, 2026 - numpy.size(array) # Total number of elements array.itemsize # Bytes per element
🌐
GeeksforGeeks
geeksforgeeks.org › numpy › python-numpy
Python NumPy - GeeksforGeeks
Elements are accessed using square brackets [] and arrays are commonly created from Python lists. NumPy arrays are created using the np.array() function.
Published: June 12, 2026
🌐
TutorialsPoint
tutorialspoint.com › numpy › numpy_array_size.htm
NumPy - Array Size
NumPy provides the size attribute to check the number of elements in an array. This attribute returns an integer representing the total number of elements, regardless of its shape.