Created
February 15, 2019 12:15
-
-
Save Robofied/c688de638fd58393b9db20a2e76a22d2 to your computer and use it in GitHub Desktop.
Numpy
This file contains 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
## 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]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment