← Back to NumPy Course | Chapter 4: Indexing & Slicing | Lesson 7 of 7

Fancy Indexing कैसे करें

एक साथ किसी भी order में कई elements pick करने के लिए positions की एक list pass करें।

In this page:

  1. Fancy Indexing
Syntax
python
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

python
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. #}
आम गलतियां
  1. एक copy की बजाय एक view की उम्मीद करना
  2. जहाँ एक list चाहिए वहाँ एक tuple pass करना
  3. 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:

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.