1

I want to basically do this:

data = np.arange(25).reshape(5, 5)
print(data)
>> [[ 0  1  2  3  4]
 [ 5  6  7  8  9]
 [10 11 12 13 14]
 [15 16 17 18 19]
 [20 21 22 23 24]]

Then it would cut it somehow, and I would end up with this

[[6 7 8]
[11 12 13]
[16 17 18]]

I tried using colons but I have no idea how they work, (like data = data(1:3, 4:5))

1
  • This is just an extension of basic Python list indexing alist[1:10]. Commented Jul 2, 2020 at 15:56

1 Answer 1

1

You're on the right track; just use brackets for array subscripting and the same indices for both dimensions of the array:

import numpy as np

data = np.arange(25).reshape(5, 5)
print(data)

print(data[1:4, 1:4])

outputs

[[ 0  1  2  3  4]
 [ 5  6  7  8  9]
 [10 11 12 13 14]
 [15 16 17 18 19]
 [20 21 22 23 24]]

[[ 6  7  8]
 [11 12 13]
 [16 17 18]]
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.