Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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