Numpy size() function | Python Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report numpy.size() function in Python is used to count the number of elements in a NumPy array. You can use it to get the total count of all elements, or to count elements along a specific axis, such as rows or columns in a multidimensional array. This makes it useful when quickly trying to understand the shape or structure of the given data.Syntax:numpy.size(arr, axis=None)Where: arr is input data in the form of an array.axis represent along which the elements (rows or columns) are counted. The function returns an integer as an output representing the number of elements. Example Usages of numpy.size() Function1. To Find Total Number of ElementsHere we create a 2D array arr with 2 rows and 4 columns and use np.size() function which will return the total number of elements in the array. Python import numpy as np arr = np.array([[1, 2, 3, 4], [5, 6, 7, 8]]) print(np.size(arr)) Output:82. To Count the Elements Along a Specific AxisHere 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. Python 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)) Output:243. To Count Elements in a 3D ArrayIn this case we are working with a 3D array having the shape (2, 2, 2). Here:axis=0 refers to the number of blocks (first level of depth).axis=1 refers to the number of rows in each block.axis=2 refers to the number of columns in each row. Python import numpy as np arr = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) print(np.size(arr)) print(np.size(arr, 0)) print(np.size(arr, 1)) print(np.size(arr, 2)) Output:8222The numpy.size() function is a tool to understand how many elements exist in your array whether it's one-dimensional or multi-dimensional. It's helpful when you're working with large datasets and want to inspect structure or dimensions. Comment More info S sanjoy_62 Follow Improve Article Tags : Python Python-numpy Explore Python FundamentalsPython Introduction 3 min read Input and Output in Python 4 min read Python Variables 5 min read Python Operators 5 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 7 min read Python Functions 5 min read Recursion in Python 6 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 5 min read Python Tuples 4 min read Dictionaries in Python 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 6 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 12 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 6 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library- Tutorial 4 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 7 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 3 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like