size() function in Numpy Python by R4R Team

- size() is a Python Numpy attribute that find the size or number of items in the given array.

Example-

array is [1 2 3 4]
size is 4

array is
[[1 2]
[3,4]
[5,6]]
size is 6

Syntax-

n=np.size(array)


program-

#import numpy
import numpy as np

l=[1,2,3,4]
arr=np.array(l)
print("Array isn",arr)
print("Size is",arr.size)

l=[[1,2,3],[3,2,1],[1,0,1]]
arr=np.array(l)
print("nArray isn",arr)
print("Size is",arr.size)

l=[[[1,2],[2,1]],[[3,4],[4,3]]]
arr=np.array(l)
print("nArray isn",arr)
print("Size is",arr.size)


output-

Array is
[1 2 3 4]
Size is 4

Array is
[[1 2 3]
[3 2 1]
[1 0 1]]
Size is 9

Array is
[[[1 2]
[2 1]]

[[3 4]
[4 3]]]
Size is 8


-In this program, we have a three list which we convert into the numpy array.
-then size(array) return the number of items in the given array.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!