Array Attributes in Python in Hindi

Arpit Nageshwar
⏰ 2 min read

Array Attributes in Python in Hindi – Array के Attributes क्या होते हैं?

Table of Contents

जब हम Python में NumPy की मदद से array बनाते हैं, तो सिर्फ उसमें data store करना ही काफी नहीं होता। कई बार हमें यह भी जानना पड़ता है कि array का structure कैसा है — उसमें कितने elements हैं, कितने dimensions हैं, या उसका data type क्या है। इन्हीं सब जानकारियों को Array Attributes कहा जाता है।

Introduction to Array Attributes in Hindi – Array Attributes का परिचय

Array Attributes दरअसल कुछ ऐसी built-in properties होती हैं, जो हमें किसी NumPy array के बारे में जानकारी देती हैं — बिना उसके अंदर के data को बदले। यानी attribute सिर्फ array की "पहचान" बताता है, जैसे उसका shape कैसा है, dimension कितनी है, कुल कितने elements हैं, और उनमें किस तरह का data रखा गया है।

इसे ऐसे समझिए — मान लीजिए आपके पास एक box है जिसमें कुछ सामान रखा है। अब अगर कोई पूछे कि box में कितने compartments हैं, उसका size क्या है, और अंदर किस तरह की चीज़ें रखी हैं — तो यही जानकारी attributes की तरह काम करती है, बिना box के अंदर का सामान निकाले।

Python में array attributes को access करने के लिए किसी function को call करने की जरूरत नहीं पड़ती। इन्हें सीधे array के नाम के साथ dot (.) लगाकर पढ़ा जाता है, जैसे array_name.shape या array_name.ndim

सबसे पहले एक simple NumPy array बनाते हैं, जिस पर आगे सारे attributes apply करेंगे:


import numpy as np

arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr)

यह एक 2D array है जिसमें 2 rows और 3 columns हैं। अब देखते हैं कि इस array से जुड़े कौन-कौन से attributes निकाले जा सकते हैं।

NumPy Array 1 2 3 4 5 6 arr.shape → (2, 3)

यह image एक 2 rows और 3 columns वाले NumPy array की structure दिखा रही है, जिसका shape (2, 3) है।

Array Attributes in Hindi – Shape, Dimension, Size और Data Type

अब बारी है array के सबसे ज्यादा use होने वाले चार attributes को detail में समझने की। यही चार attributes exam में भी सबसे ज्यादा पूछे जाते हैं।

1. Shape (shape):
Shape attribute यह बताता है कि array में कितनी rows और कितने columns हैं। इसका output हमेशा एक tuple के रूप में मिलता है।


import numpy as np

arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr.shape)   # Output: (2, 3)

यहाँ output (2, 3) का मतलब है कि array में 2 rows और 3 columns मौजूद हैं।

2. Dimension (ndim):
ndim attribute यह बताता है कि array कितने dimensions का है — यानी वह 1D है, 2D है या 3D। Simple शब्दों में, यह array की "depth" बताता है।


import numpy as np

arr1 = np.array([1, 2, 3])
arr2 = np.array([[1, 2, 3], [4, 5, 6]])

print(arr1.ndim)   # Output: 1
print(arr2.ndim)   # Output: 2

ऊपर arr1 एक 1D array है इसलिए उसका dimension 1 है, जबकि arr2 rows और columns दोनों में होने की वजह से 2D array है।

3. Size (size):
size attribute array में मौजूद कुल elements की संख्या बताता है — चाहे array कितने भी dimensions का क्यों न हो।


import numpy as np

arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr.size)   # Output: 6

यहाँ array में कुल 6 elements हैं (2 rows × 3 columns = 6), इसलिए size का output 6 आया।

4. Data Type (dtype):
dtype attribute यह बताता है कि array के अंदर किस तरह का data store है — जैसे integer, float या string। यह जानना इसलिए जरूरी है क्योंकि NumPy array में सभी elements का data type एक जैसा ही होता है।


import numpy as np

arr1 = np.array([1, 2, 3])
arr2 = np.array([1.5, 2.5, 3.5])

print(arr1.dtype)   # Output: int64
print(arr2.dtype)   # Output: float64

इसके अलावा एक और उपयोगी attribute है itemsize, जो यह बताता है कि array के हर element को store करने में कितने bytes लगते हैं:


import numpy as np

arr = np.array([1, 2, 3])
print(arr.itemsize)   # Output: 8 (bytes)
shape (2, 3) ndim 2 size 6 dtype int64 [[1, 2, 3], [4, 5, 6]]

यह image दिखाती है कि एक ही array से shape, ndim, size और dtype जैसे अलग-अलग attributes कैसे निकाले जा सकते हैं।

Summary Table of Array Attributes in Hindi – Array Attributes की Summary Table

Exam की तैयारी करते समय सारे attributes को याद रखना आसान बनाने के लिए नीचे एक छोटी summary table दी गई है, जिसमें हर attribute का काम एक लाइन में समझाया गया है।

Attribute क्या बताता है Example Output
shape Array में rows और columns की संख्या (2, 3)
ndim Array के dimensions की संख्या 2
size Array में कुल elements की संख्या 6
dtype Array में store data का type int64
itemsize हर element को store करने में लगने वाली bytes 8

इस table को अगर आप एक बार अच्छे से समझ लें, तो exam में shape, dimension, size या data type से जुड़ा कोई भी सवाल आसानी से solve किया जा सकता है — क्योंकि सभी attributes का logic लगभग एक जैसा ही रहता है, बस उनका output अलग-अलग जानकारी देता है।

Arpit Nageshwar

✍️ Arpit Nageshwar

Post-graduated | Web Developer | +3 yr Experience | IIT Kharagpur Certified