Last active
August 13, 2020 00:32
-
-
Save KenoLeon/99a66b764901122a2a38b7e6f606f278 to your computer and use it in GitHub Desktop.
Indexing_Slicing_Numpy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| linear_spaced_array = np.linspace(0, 100, 11, dtype=np.uint8) | |
| # >>> [ 0 10 20 30 40 50 60 70 80 90 100] | |
| # -------------- SIMPLE INDEXING -------------- | |
| firstN = linear_spaced_array[:4] | |
| # >>> [ 0 10 20 30] | |
| lastN = linear_spaced_array[-4:] | |
| # >>> [ 70 80 90 100] | |
| # -------------- SIMPLE SLICING -------------- | |
| sliceBetween = linear_spaced_array[2:6] | |
| # >>> [20 30 40 50] | |
| # -------------- SIMPLE CONDITIONAL -------------- | |
| lessthan = linear_spaced_array[linear_spaced_array < 50] | |
| # >>> [ 0 10 20 30 40] | |
| # -------------- SIMPLE ASSIGNEMENT -------------- | |
| linear_spaced_array[linear_spaced_array > 50] = 100 | |
| # >>> [ 0 10 20 30 40 50 100 100 100 100 100] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment