1D Array की Slicing
Slicing start:stop:step इस्तेमाल करके elements की एक range लेता है।
In this page:
Syntax
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
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. #}
आम गलतियां
- यह उम्मीद करना कि stop included होगा
- यह भूल जाना कि slices original के साथ memory share करते हैं
- एक 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: