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

2D Indexing कैसे करें

दो numbers, row फिर column, एक table में एक single cell select करते हैं।

In this page:

  1. 2D Indexing
Syntax
python
arr[row, col]

2D Indexing

एक 2-D array के एक element तक पहुँचने के लिए arr[row, col] इस्तेमाल करें। यह comma form chained arr[row][col] से faster और clearer है। arr[1] जैसा एक single index पूरी row return करता है।

Note: arr[1][2] और arr[1, 2] दोनों काम करते हैं, लेकिन comma version दो की बजाय एक lookup करता है।

उदाहरण: 2D indexing

python
import numpy as np

m = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print(m[1, 2])
print(m[0])
print(m[2][0])

# Output:
# 6
# [1 2 3]
# 7
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. row और column order swap करना
  2. slices assign करते वक्त chained indexing इस्तेमाल करना
  3. यह उम्मीद करना कि arr[1] एक single value return करेगा
चैप्टर सारांश
  • arr[row, col] इस्तेमाल करें
  • एक index पूरी row return करता है
  • Rows पहले आती हैं फिर columns
  • Comma indexing preferred है
🔒

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.