Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Simple without stride and slice
- print(y[1,2])
- #[Output]:
- #9
- ## Using ":" will go from start to end
- ## Without stride
- print("This is without stride-:")
- print(y[:])
- print("\n")
- ## With stride
- print("This is with the stride of 3-:")
- print(y[::3])
- #[Output]:
- #This is without stride-:
- #[[ 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 25 26 27]
- # [28 29 30 31 32 33 34]]
- #[Output]:
- #This is with the stride of 3-:
- #[[ 0 1 2 3 4 5 6]
- # [21 22 23 24 25 26 27]]
- ## It will extract rows from 1 to 4 and for all columns
- print(y[1:5,:])
- #[Output]:
- #[[ 7 8 9 10 11 12 13]
- # [14 15 16 17 18 19 20]
- # [21 22 23 24 25 26 27]
- # [28 29 30 31 32 33 34]]
- ## If we want to choose particular columns
- print(y[1:5:2,::3])
- #[Output]:
- #[[ 7 10 13]
- # [21 24 27]]
Add Comment
Please, Sign In to add comment