Skip to content

Instantly share code, notes, and snippets.

@Robofied
Created February 15, 2019 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Robofied/c688de638fd58393b9db20a2e76a22d2 to your computer and use it in GitHub Desktop.
Save Robofied/c688de638fd58393b9db20a2e76a22d2 to your computer and use it in GitHub Desktop.
Numpy
## 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