Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created January 19, 2021 06:19
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 IndhumathyChelliah/31aade5af9d90ec10950269910ac8365 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/31aade5af9d90ec10950269910ac8365 to your computer and use it in GitHub Desktop.
import numpy as np
a1=np.array([[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]])
print (a1)
#Output:
[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]
[12 13 14 15]]
#Accessing elements which are greater than 5
print (a1[a1>5])
#Output:[ 6 7 8 9 10 11 12 13 14 15]
#Accessing elements which are greater than 5 and less than 10
print (a1[(a1>5)&(a1<10)])
#Output:[6 7 8 9]
#Modifying elements which are greater than 11 by adding 100 to it.
a1[a1>11]+=100
print (a1)
#Output:
[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]
[112 113 114 115]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment