You can get the second dimension of the array as:
a.shape[1]
Answer from DaveP on Stack Overflowpython 3.x - Numpy: Size of a 2D array matrix? - Stack Overflow
Copydef size(a, axis=None): """ Return the number of elements along a given axis. Parameters ---------- a : array_like Input data. axis : int, optional Axis along which the elements are counted. By default, give the total number of elements. Returns ------- element_count : int Number of elements ... More on stackoverflow.com
numpy shape (100,) vs (100,1)
A numpy array of shape (100,) has one dimension, while an array of shape (100, 1) has two dimensions. The difference is also immediately observable: >>> import numpy as np >>> arr_1 = np.random.randint(1, 10, size=(5,)) >>> print(arr_1.ndim) 1 >>> print(arr_1) [7 9 2 3 3] >>> arr_2 = np.random.randint(1, 10, size=(5,1)) >>> print(arr_2.ndim) 2 >>> print(arr_2) [[5] [4] [4] [2] [4]] More on reddit.com
Is it possible to grab the last element of a numpy array with a negative slice?
You can't loop from negative to postive slice values as they don't "wrap". a[-2:2] would also give an empty array. More on reddit.com
Numpy array is the worst part of python.
Numpy is unnecessarily imperative for what it is supposed to do. A very high-level declarative API defining array transformations would be awesome. I want to be able to tell it to partition a 2D matrix in NxM subarrays and then absolutely sort everything on it without juggling index/slicing ... More on reddit.com
NumPy
numpy.org › doc › stable › reference › arrays.ndarray.html
The N-dimensional array (ndarray) — NumPy v2.5 Manual
A 2-dimensional array of size 2 x 3, composed of 4-byte integer elements:
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 - Size of the first dimension of a NumPy array: len() 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) # [[ 0 1 2 3] # [ 4 5 6 7] # [ 8 9 10 11]] a_3d = np.arange(24).reshape((2, 3, 4)) print(a_3d) # [[[ 0 1 2 3] # [ 4 5 6 7] # [ 8 9 10 11]] # # [[12 13 14 15] # [16 17 18 19] # [20 21 22 23]]] source: numpy_ndim_shape_size.py ·
Finxter
blog.finxter.com › home › learn python blog › how to get the length of a 2d numpy array
How to Get the Length of a 2D NumPy Array - Be on the Right Side of Change
October 17, 2022 - 💡Note: The size function returns the number of elements along a given axis. This example uses the len() and zip() functions to determine the length of a 2D array. To run the code below error-free, the NumPy library must be installed.
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.
Stack Overflow
stackoverflow.com › questions › 65552509 › numpy-size-of-a-2d-array-matrix
python 3.x - Numpy: Size of a 2D array matrix? - Stack Overflow
Both are correct outputs as the size of the array is 12.
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ma.size.html
numpy.ma.size — NumPy v2.1 Manual
Number of elements along the specified axis. ... >>> 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 › reference › generated › numpy.ma.size.html
numpy.ma.size — NumPy v2.4 Manual
Number of elements along the specified axis. ... Try it in your browser! >>> import numpy as np >>> a = np.array([[1,2,3],[4,5,6]]) >>> np.size(a) 6 >>> np.size(a,axis=1) 3 >>> np.size(a,axis=0) 2 >>> np.size(a,axis=(0,1)) 6
Medium
medium.com › @heyamit10 › numpy-ndarray-size-931a5805aedb
Understanding ndarray.size. If you think you need to spend $2,000… | by Hey Amit | Medium
February 8, 2025 - No matter how complex your array looks or how many dimensions it has, .size gives you one number: the total count of elements. This is super helpful when you’re processing data, debugging code, or ensuring your calculations align correctly. ... import numpy as np # Create a 2D array arr = np.array([[1, 2, 3], [4, 5, 6]]) # Get the size of the array print("Array size:", arr.size) # Output: 6
NumPy
numpy.org › devdocs › user › absolute_beginners.html
NumPy: the absolute basics for beginners — NumPy v2.6.dev0 Manual
Using np.newaxis will increase the dimensions of your array by one dimension when used once. This means that a 1D array will become a 2D array, a 2D array will become a 3D array, and so on.
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.ndarray.size.html
numpy.ndarray.size — NumPy v2.2 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.
GeeksforGeeks
geeksforgeeks.org › python › numpy-size-function-python
Numpy size() function | Python - GeeksforGeeks
July 12, 2025 - Here 0 is used to denote the axis as rows and 1 is used to denote axis as columns. 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))
NumPy
numpy.org › doc › 2.2 › reference › arrays.ndarray.html
The N-dimensional array (ndarray) — NumPy v2.2 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.4 › reference › arrays.ndarray.html
The N-dimensional array (ndarray) — NumPy v2.4 Manual
A 2-dimensional array of size 2 x 3, composed of 4-byte integer elements:
NumPy
numpy.org › doc › stable › reference › generated › numpy.ndarray.size.html
numpy.ndarray.size — NumPy v2.5 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.
NumPy
numpy.org › devdocs › reference › generated › numpy.ma.size.html
numpy.ma.size — NumPy v2.6.dev0 Manual
Number of elements along the specified axis. ... Try it in your browser! >>> import numpy as np >>> a = np.array([[1,2,3],[4,5,6]]) >>> np.size(a) 6 >>> np.size(a,axis=1) 3 >>> np.size(a,axis=0) 2 >>> np.size(a,axis=(0,1)) 6
OpenGenus
iq.opengenus.org › 2d-array-in-numpy
2D Arrays in NumPy (Python)
October 28, 2022 - Identity identity(r) will return an identity matrix of r row and r columns. ... Arithmetic Operations Applying scalar operations to an array. a = np.array([[1,2,3],[4,6,2],[0,7,1]]) #array with size 3x3 #Scalar operation - It will operate with scalar to each element of an array print(a+2) ...