SHARE
TWEET

Untitled

a guest Feb 17th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## Simple without stride and slice
  2. print(y[1,2])
  3.  
  4. #[Output]:
  5. #9
  6.  
  7. ## Using ":" will go from start to end
  8.  
  9. ## Without stride
  10. print("This is without stride-:")
  11. print(y[:])
  12.  
  13. print("\n")
  14.  
  15. ## With stride
  16. print("This is with the stride of 3-:")
  17. print(y[::3])
  18.  
  19. #[Output]:
  20. #This is without stride-:
  21. #[[ 0  1  2  3  4  5  6]
  22. # [ 7  8  9 10 11 12 13]
  23. # [14 15 16 17 18 19 20]
  24. # [21 22 23 24 25 26 27]
  25. # [28 29 30 31 32 33 34]]
  26.  
  27. #[Output]:
  28. #This is with the stride of 3-:
  29. #[[ 0  1  2  3  4  5  6]
  30. # [21 22 23 24 25 26 27]]
  31.  
  32.  
  33. ## It will extract rows from 1 to 4 and for all columns
  34. print(y[1:5,:])
  35.  
  36. #[Output]:
  37. #[[ 7  8  9 10 11 12 13]
  38. # [14 15 16 17 18 19 20]
  39. # [21 22 23 24 25 26 27]
  40. # [28 29 30 31 32 33 34]]
  41.  
  42.  
  43. ## If we want to choose particular columns
  44.  
  45. print(y[1:5:2,::3])
  46.  
  47. #[Output]:
  48. #[[ 7 10 13]
  49. # [21 24 27]]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top