Skip to content

Instantly share code, notes, and snippets.

@vinaykudari
Created July 25, 2018 20:24
Show Gist options
  • Save vinaykudari/df084a8a36155c024a8a3cf16846ca91 to your computer and use it in GitHub Desktop.
Save vinaykudari/df084a8a36155c024a8a3cf16846ca91 to your computer and use it in GitHub Desktop.
ufunc.at
a = np.random.randint(5,10,5)
>> a
[6 5 8 8 7]
np.add.at(a,np.flatnonzero(a>8),2) #flatnonzero returns the indices where values are >8
>> a
[6 5 10 10 9]
np.maximum.at(a,[0,1,2],60) #checks the max value
>> a
[60 60 60 10 9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment