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!!!
2 odpowiedzi
+ 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...!!!
0
It does! Like a lot lol. Thank you!