Hello guys. How are you all? I hope you all fine. In this tutorial we will learn about How to get List Shape in Python. so without wasting time lets learn about of this.
How to get List Shape in Python
- get List Shape in Python
to get List Shape in Python just Use len().By using len() you can get the number of elements in an object. So without wasting time lets learn about of this by given below example:
list1 = [[3,5,6],[4,5,6],[5,6,6]] arow = len(list1) acol = len(list1[0]) print("Rows : " + str(arow)) print("Columns : " + str(acol))
Output :Rows : 3 Columns : 3
- How to get List Shape in Python
to get List Shape in Python just Use numpy.shape().By using numpy.shape() you can get the number of elements in an object. So without wasting time lets learn about of this by given below example:
import numpy as np list1 = [1,2,3] list2 = [[1,2],[3,4]] print("Shape of list1 is : "+str(np.shape(list1))) print("Shape of list2 is : "+str(np.shape(list2)))
Output :Shape of lista is : (3,) Shape of listb is : (2, 2)
- python list shape
To get List Shape in Python just Use numpy.shape().By using numpy.shape() you can get the number of elements in an object. So without wasting time lets learn about of this by given below example:
import numpy as np list1 = [1,2,3] list2 = [[1,2],[3,4]] print("Shape of list1 is : "+str(np.shape(list1))) print("Shape of list2 is : "+str(np.shape(list2)))
Output :Shape of lista is : (3,) Shape of listb is : (2, 2)
Method 1: Use len()
By using len() you can get the number of elements in an object. So without wasting time lets learn about of this by given below example:
list1 = [[3,5,6],[4,5,6],[5,6,6]]
arow = len(list1)
acol = len(list1[0])
print("Rows : " + str(arow))
print("Columns : " + str(acol))
Output :
Rows : 3
Columns : 3
Method 2: Use numpy.shape()
By using numpy.shape() you can get the number of elements in an object. So without wasting time lets learn about of this by given below example:
import numpy as np
list1 = [1,2,3]
list2 = [[1,2],[3,4]]
print("Shape of list1 is : "+str(np.shape(list1)))
print("Shape of list2 is : "+str(np.shape(list2)))
Output :
Shape of lista is : (3,)
Shape of listb is : (2, 2)
Conclusion
It’s all About this Tutorial. Hope all methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you?
Also, Read