Numpy size() function | Python
Last Updated :
29 Jul, 2021
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 :
Python3
import numpy as np
arr = np.array([[ 1 , 2 , 3 , 4 ], [ 5 , 6 , 7 , 8 ]])
print (np.size(arr))
|
Code #2 :
Python3
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 ))
|
Share your thoughts in the comments
Please Login to comment...