# Numpy size() function | Python

## Numpy size() function | Python

In Python, numpy.size() function count the number of elements along a given axis.

Syntax: numpy.size(arr, axis=None)
Parameters:
arr: [array_like] Input data.
axis: [int, optional] Axis(x,y,z) along which the elements(rows or columns) are counted. By default, give the total number of elements in a array
Returns: [int] Return the number of elements along a given axis.

Code #1 :

 `# Python program explaining` `# numpy.size() method` `# importing numpy` `import` `numpy as np` `# Making a random array` `arr ``=` `np.array([[``1``, ``2``, ``3``, ``4``], [``5``, ``6``, ``7``, ``8``]])` `# By default, give the total number of elements.` `print``(np.size(arr))`

Output:

`8`

Code #2 :

 `# Python program explaining` `# numpy.size() method` `# importing numpy` `import` `numpy as np` `# Making a random array` `arr ``=` `np.array([[``1``, ``2``, ``3``, ``4``], [``5``, ``6``, ``7``, ``8``]])` `# count the number of elements along the axis.` `# Here rows and columns are being treated` `# as elements` `#gives no. of rows along x-axis` `print``(np.size(arr, ``0``))` `#gives no. of columns along y-axis` `print``(np.size(arr, ``1``))`

Output:

```2
4```

Last Updated on November 11, 2021 by admin

## Ways to remove i’th character from string in PythonWays to remove i’th character from string in Python

Ways to remove i’th character from string in Python In Python it is all known that string is immutable and hence sometimes poses visible restrictions while coding the constructs that are required in day-day programming. This article presents one such

## Create a DataFrame from a Numpy array and specify the index column and column headersCreate a DataFrame from a Numpy array and specify the index column and column headers

Create a DataFrame from a Numpy array and specify the index column and column headers Let us see how to create a DataFrame from a Numpy array. We will also learn how to specify the index and the column headers

## Python PIL – Image.save() methodPython PIL – Image.save() method

Python PIL | Image.save() method PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides

## Difference between input() and raw_input() functions in PythonDifference between input() and raw_input() functions in Python

Difference between input() and raw_input() functions in Python Developers often have a need to interact with users, either to get data or to provide some sort of result. Most programs today use a dialog box as a way of asking

## Python infinityPython infinity

Python infinity As ironic as it may seem infinity is defined as an undefined number that can either be a positive or negative value. All arithmetic operations performed on an infinite value always lead to an infinite number, say it

## Python string len() methodPython string len() method

Python string len() method Python len() function is an inbuilt function in Python programming language that returns the length of the string. Syntax: len(string) Parameters: It takes string as the parameter. Return Value:     It returns an integer which

## Check if a value exists in a DataFrame using in & not in operator in Python-PandasCheck if a value exists in a DataFrame using in & not in operator in Python-Pandas

In this article, Let’s discuss how to check if a given value exists in the dataframe or not. Method 1 : Use in operator to check if an element exists in dataframe. # import pandas library import pandas as pd

## Python – geometry method in TkinterPython – geometry method in Tkinter

Python | geometry method in Tkinter Tkinter is a Python module that is used to develop GUI (Graphical User Interface) applications. It comes along with Python, so you do not have to install it using the pip command. Tkinter provides many methods; one