Share your knowledge with other learners . . . Login Register

NumPy module में ndarray की shape property बताती है कि , array की dimension क्या है और हर dimension में कितने elements है।


shape property एक tuple return करती है , जिसमे दो values होती है - array की dimension और हर index पर कितने elements हैं।

NumPy Get array shape

Copy Fullscreen Close Fullscreen Run
#import numpy module.
import numpy as np
#check for one dimensional array.
arr = np.array([10, 20, 30, 40, 50])
print(arr.shape)

#now chack for 2 - dimensional array.
arr2 = np.array([ [10, 20, 30], [40, 50, 60], [70, 80, 90], [100, 110, 120] ])
print(arr2.shape)
Output
C:\Users\Rahulkumar\Desktop\python>python module_numpy.py
(5,)
(4, 3)

Note : 1 - dimensional array के लिए tuple में एक ही value होती है , जो कि array की length बताती है। जैसा कि आप example में देख रहे हैं।

Output में (4,3) आया है , मतलब array में 4 dimensions (array elements) है, और dimension में 3 elements है।

Important *

याद रहे कि , अगर inner arrays (dimensions) में no. of elements same नहीं है तो tuple में सिर्फ एक ही value होगी जो dimensions (array elements) की सख्यां होगी।

Copy Fullscreen Close Fullscreen Run
import numpy as np
arr2 = np.array([ [10, 20, 30, 4], [40, 50, 60], [70, 80, 90]])
print(arr2.shape)
Output
C:\Users\Rahulkumar\Desktop\python>python module_numpy.py
(3,)

Example देखकर आप समझ गए होंगे कि shape property किस तरह से work करती है।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers