Guest User

Untitled

a guest
Feb 17th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import numpy as np
  2.  
  3. x = np.arange(10,1,-1)
  4. print(x)
  5.  
  6. #[Output]:
  7. #[10 9 8 7 6 5 4 3 2]
  8.  
  9.  
  10. print(x[np.array([3,3,4,7])])
  11.  
  12. #[Output]:
  13. #[7 7 6 3]
  14.  
  15.  
  16. ## Negative indexing is the same as work with single indexes
  17.  
  18. x[np.array([3,3,-3,8])]
  19.  
  20. #[Output]:
  21. #array([7, 7, 4, 2])
  22.  
  23.  
  24. ## Index out of range will give an error
  25. x[np.array([3,3,19,8])]
  26.  
  27.  
  28. #[Output]:
  29. #---------------------------------------------------------------------------
  30. #IndexError Traceback (most recent call last)
  31. #<ipython-input-5-9eeb5decb0c8> in <module>()
  32. #----> 1 x[np.array([3,3,19,8])]
  33.  
  34. #IndexError: index 19 is out of bounds for axis 1 with size 9
  35.  
  36.  
  37. x[np.array([[1,1],[2,3]])]
  38.  
  39. #[Output]:
  40. #array([[9, 9],
  41. # [8, 7]])
Add Comment
Please, Sign In to add comment