← Back to NumPy Course | Chapter 3: Array Attributes | Lesson 1 of 6

shape क्या है

shape आपको बताता है array की कितनी rows, columns, वगैरह हैं।

In this page:

  1. shape
Syntax
python
arr.shape    # (rows, cols)

shape

shape attribute हर dimension की length देने वाला एक tuple है। एक 2-by-3 matrix का shape (2, 3) है। shape को assign करना या reshape इस्तेमाल करना data बदले बिना layout बदलता है।

Note: 5 length वाले एक 1-D array का shape एक trailing comma के साथ (5,) है, क्योंकि यह एक tuple है।

उदाहरण: shape

python
import numpy as np

m = np.array([[1, 2, 3], [4, 5, 6]])
print(m.shape)
print("rows:", m.shape[0], "cols:", m.shape[1])
print(np.array([1, 2, 3]).shape)

# Output:
# (2, 3)
# rows: 2 cols: 3
# (3,)
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह भूल जाना कि shape एक tuple है, number नहीं
  2. (5,) को (5, 1) से confuse करना
  3. shape को एक method समझकर इसे call करना
चैप्टर सारांश
  • shape dimension sizes का एक tuple है
  • यह एक attribute है इसलिए कोई parentheses नहीं
  • 1-D shapes (n,) जैसे दिखते हैं
  • shape का product size के बराबर है
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.