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

1D Array की Slicing

Slicing start:stop:step इस्तेमाल करके elements की एक range लेता है।

In this page:

  1. Slicing 1D
Syntax
python
arr[start:stop:step]

Slicing 1D

arr[start:stop:step] start से लेकर stop तक लेकिन इसे शामिल किए बिना elements का एक view return करता है। छोड़े गए parts default से beginning, end, और step 1 लेते हैं। एक negative step backwards चलता है, इसलिए [::-1] array reverse करता है।

Note: Slices views हैं, इसलिए एक slice edit करना original array बदल देता है।

उदाहरण: Slicing 1D

python
import numpy as np

a = np.arange(10)
print(a[2:6])
print(a[::3])
print(a[::-1])
s = a[:3]
s[0] = 100
print("original changed:", a[:3])

# Output:
# [2 3 4 5]
# [0 3 6 9]
# [9 8 7 6 5 4 3 2 1 0]
# original changed: [100   1   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. #}
आम गलतियां
  1. यह उम्मीद करना कि stop included होगा
  2. यह भूल जाना कि slices original के साथ memory share करते हैं
  3. एक zero step इस्तेमाल करना
चैप्टर सारांश
  • Slices start:stop:step हैं
  • Stop excluded है
  • Slices copies नहीं views हैं
  • [::-1] reverse करता है
🔒

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.