Fancy Indexing कैसे करें
एक साथ किसी भी order में कई elements pick करने के लिए positions की एक list pass करें।
In this page:
Syntax
arr[[index1, index2, index3]]
matrix[[row1, row2], [col1, col2]]
Fancy Indexing
एक integer array या list से index करना दिए गए order में exact वे positions select करता है, और repeats allowed हैं। 2-D arrays पर, दो index arrays matching row और column pairs pick करते हैं। Fancy indexing एक copy return करता है।
Note:
Rows reorder करने के लिए इसे इस्तेमाल करें: m[[2, 0, 1]]।
उदाहरण: Fancy indexing
import numpy as np
a = np.array([10, 20, 30, 40, 50])
print(a[[0, 2, 4]])
print(a[[4, 4, 0]])
m = np.arange(9).reshape(3, 3)
print(m[[0, 1, 2], [2, 1, 0]])
# Output:
# [10 30 50]
# [50 50 10]
# [2 4 6]
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. #}
आम गलतियां
- एक copy की बजाय एक view की उम्मीद करना
- जहाँ एक list चाहिए वहाँ एक tuple pass करना
- Index arrays की lengths mismatched रखना
चैप्टर सारांश
- ints की lists या arrays से index करें
- Order और repeats preserve होते हैं
- एक copy return करता है
- Paired arrays 2-D arrays पर cells select करते हैं
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: