transpose() से Array पलटना
transpose() एक array को flip करता है ताकि इसकी rows columns बन जाएँ और columns rows बन जाएँ।
In this page:
Syntax
arr.transpose()
arr.T
np.transpose(arr, axes)
transpose()
एक 2-D array के लिए, transpose दो axes swap करता है; shortcut .T attribute है। Higher dimensions के लिए आप एक custom axis order pass कर सकते हैं। Result same data का एक view है।
Note:
एक 1-D array .T से unchanged रहता है; पहले इसे एक 2-D array में reshape करें।
उदाहरण: transpose()
import numpy as np
m = np.array([[1, 2, 3], [4, 5, 6]])
print(m.shape)
print(m.T)
print(m.T.shape)
# Output:
# (2, 3)
# [[1 4]
# [2 5]
# [3 6]]
# (3, 2)
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. #}
आम गलतियां
- यह उम्मीद करना कि .T एक 1-D array को एक column में बदल देगा
- यह भूल जाना कि result एक view है
- 3-D arrays के लिए गलत axes order इस्तेमाल करना
चैप्टर सारांश
- .T rows और columns swap करता है
- np.transpose एक axes order accept करता है
- एक view return करता है
- 1-D arrays नहीं बदलते
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: