shape क्या है
shape आपको बताता है array की कितनी rows, columns, वगैरह हैं।
In this page:
Syntax
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
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. #}
आम गलतियां
- यह भूल जाना कि shape एक tuple है, number नहीं
- (5,) को (5, 1) से confuse करना
- shape को एक method समझकर इसे call करना
चैप्टर सारांश
- shape dimension sizes का एक tuple है
- यह एक attribute है इसलिए कोई parentheses नहीं
- 1-D shapes (n,) जैसे दिखते हैं
- shape का product size के बराबर है