2D Array की Slicing
एक sub-table निकालने के लिए एक साथ rows और columns slice करें।
In this page:
Syntax
arr[row_start:row_stop, col_start:col_stop]
arr[:, col]
arr[row, :]
Slicing 2D
commas से separated प्रति axis एक slice दें: arr[rows, cols]। एक अकेला colon उस axis पर सब कुछ मतलब है। यह rows, columns, या rectangular blocks extract करना आसान बनाता है।
Note:
m[:, 1] पूरा second column select करता है।
उदाहरण: Slicing 2D
import numpy as np
m = np.arange(1, 13).reshape(3, 4)
print(m)
print("column 1:", m[:, 1])
print("first two rows, last two cols:")
print(m[:2, 2:])
# Output:
# [[ 1 2 3 4]
# [ 5 6 7 8]
# [ 9 10 11 12]]
# column 1: [ 2 6 10]
# first two rows, last two cols:
# [[3 4]
# [7 8]]
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. #}
आम गलतियां
- पूरी axis के लिए colon भूल जाना
- row और column slices mix up करना
- एक slice modify करना और यह भूल जाना कि यह एक view है
चैप्टर सारांश
- arr[row_slice, col_slice] इस्तेमाल करें
- एक colon मतलब सब कुछ
- m[:, j] एक column है
- Results views हैं
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: