Click here to Skip to main content
16,022,297 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
code:

import numpy as np
x=np.array([[1,2,3,5,6],[7,8,9,0,1],[3,7,0,7,6]])
print(x)
print(x[1:4,2:])

Output:

[[1 2 3 5 6]
[7 8 9 0 1]
[3 7 0 7 6]]

[[9 0 1]
[0 7 6]]

What I have tried:

I was just trying slicing can somebody explain the mechanism of this code
Posted

1 solution

The second print statement
Python
print(x[1:4,2:])

instructs the system to print the array entries with index 1,2 and 3, selecting elements 2, 3, 4 ... etc. So if you examine the array x[1] is [7,8,9,0,1] and entries 2 to the end are 9,0 and 1. You can see the same for x[2].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900