0

NumPy's 2D array:

testing = np.array([
     [   0,    0,    2,    5,    0],
     [1478, 3877, 3674, 2328, 2539],
     [1613, 4088, 3991, 6461, 2691],
     [1560, 3392, 3826, 4787, 2613],
     [1608, 4802, 3932, 4477, 2705],
     [1576, 3933, 3909, 4979, 2685],
     [  95,  229,  255,  496,  201],
     [   2,    0,    1,   27,    0],
     [1438, 3785, 3589, 4174, 2215],
     [1342, 4043, 4009, 4665, 3033]
])

If I do the following:

print testing[1:3, 3:5]

I get the following:

[[2328 2539] [6461 2691]]

And I really can't understand how did I get an output like this.

Could anyone mind explaining me how does this work? And how is the output like that?

1

1 Answer 1

0

In your case with [1:3] you sliced the second and third row

( remember index starts at 0 and 1:3 = 1,2 ; 3 is not included )

    [1478, 3877, 3674, 2328, 2539],
    [1613, 4088, 3991, 6461, 2691]

And with [3:5] you sliced the fourth and fifth column of even that selection. which would be by the same reasoning as above:

    [2328, 2539],
    [6461, 2691]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.