If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
NumPy module में ndarray की shape property बताती है कि , array की dimension क्या है और हर dimension में कितने elements है।
shape property एक tuple return करती है , जिसमे दो values होती है - array की dimension और हर index पर कितने elements हैं।
#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)
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 है।
याद रहे कि , अगर inner arrays (dimensions) में no. of elements same नहीं है तो tuple में सिर्फ एक ही value होगी जो dimensions (array elements) की सख्यां होगी।
import numpy as np
arr2 = np.array([ [10, 20, 30, 4], [40, 50, 60], [70, 80, 90]])
print(arr2.shape)
C:\Users\Rahulkumar\Desktop\python>python module_numpy.py (3,)
Example देखकर आप समझ गए होंगे कि shape property किस तरह से work करती है।
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook