Numpy 2D Array Slicing | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Numpy 2D Array Slicing

import numpy as np a = np.array([[8, 6, 2], [4, 9, 7], [2, 5, 5]]) print (a[1:3, 1:3]) Could someone explain how the output is: [[9, 7] [5, 5]] Thank y’all!!!

16th Aug 2019, 6:57 AM
ScienceLuke7
ScienceLuke7 - avatar
2 Answers
+ 1
Size of a is 3*3=9 elements. Slicing command a([ 1:3], [1:3]) indicates take elements - (1st row 1st element to 3rd element - 9,7; 2 nd row 1st element to 3rd element - 5,5). As there is no 3rd row, elements in 1st row and 2nd row are only printed. Note that, no elements in 0th row;0th column were printed. In python index of elements start from 0. Hope this helps...!!!
16th Aug 2019, 9:42 AM
Kuri
Kuri - avatar
0
It does! Like a lot lol. Thank you!
16th Aug 2019, 6:12 PM
ScienceLuke7
ScienceLuke7 - avatar