Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- x = np.arange(10,1,-1)
- print(x)
- #[Output]:
- #[10 9 8 7 6 5 4 3 2]
- print(x[np.array([3,3,4,7])])
- #[Output]:
- #[7 7 6 3]
- ## Negative indexing is the same as work with single indexes
- x[np.array([3,3,-3,8])]
- #[Output]:
- #array([7, 7, 4, 2])
- ## Index out of range will give an error
- x[np.array([3,3,19,8])]
- #[Output]:
- #---------------------------------------------------------------------------
- #IndexError Traceback (most recent call last)
- #<ipython-input-5-9eeb5decb0c8> in <module>()
- #----> 1 x[np.array([3,3,19,8])]
- #IndexError: index 19 is out of bounds for axis 1 with size 9
- x[np.array([[1,1],[2,3]])]
- #[Output]:
- #array([[9, 9],
- # [8, 7]])
Add Comment
Please, Sign In to add comment