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

1D Indexing कैसे करें

position से एक element पाने के लिए square brackets में एक number इस्तेमाल करें, zero से शुरू होते हुए।

In this page:

  1. 1D Indexing
Syntax
python
arr[index]
arr[-1]

1D Indexing

एक 1-D array index करना एक list जैसे काम करता है: arr[0] पहला element है। array को in place modify करने के लिए आप एक index को assign भी कर सकते हैं। अंत से आगे जाना IndexError raise करता है।

Note: Indexing एक NumPy scalar return करता है जैसे np.int64, एक plain Python int नहीं।

उदाहरण: 1D indexing

python
import numpy as np

a = np.array([10, 20, 30, 40])
print(a[0], a[2])
a[1] = 99
print(a)

# Output:
# 10 30
# [10 99 30 40]
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. 0 की बजाय 1 से शुरू करना
  2. last element से आगे index करना
  3. यह भूल जाना कि assignment original array बदलता है
चैप्टर सारांश
  • Indices 0 से शुरू होती हैं
  • arr[i] एक element पढ़ता या assign करता है
  • Out-of-range IndexError raise करता है
  • Results NumPy scalars हैं
🔒

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.