So I was given a worksheet exercise as follows:
-
Given the following grid of 25 values, extract the central 3 x 3 sub-grid of
9
s from the larger grid using thesplit()
function:1 2 3 4 5 1 9 9 9 5 1 9 9 9 5 1 9 9 9 5 1 2 3 4 5
And the solution is as follows:
x = np.array([[1,2,3,4,5],
[1, 9, 9, 9, 5],
[1, 9, 9, 9, 5],
[1, 9, 9, 9, 5],
[1, 2, 3, 4, 5]])
x1, x2, x3 = np.split(x, [1, 4])
y1, y2, y3 = np.split(x2, [1, 4], axis = 1)
print(y2)
My question is, why is it [1, 4] in the brackets? does this refer to the element number, if so, should it not be [1, 3]?
Sorry if this seems like a very simple question - am still super new to coding!!
Thanks in advance :)
source https://stackoverflow.com/questions/74524188/understanding-numpy-split-function-to-extract-sub-grid
Comments
Post a Comment