Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
add.at() method
#2
This is how at() method works in the above case
np.add.at(x,i,1)
Here x will be array with all zeros as known,
Then i will be indexing to the array x, suppose you have given i = range(0,5), then this considers x[0],x[1],x[2],x[3],x[4].. so i is used to provide index for the array you need to change. i can be tuple also.
As you have given 1 as third attribute ,it adds one to the above indexes..

suppose your code was like this
import numpy as np
x = np.zeros(10)
i = range(0,5)
np.add.at(x, i, 1)
print(x)

output:
[1. 1. 1. 1. 1. 0. 0. 0. 0. 0.]
there fore adding one to all the indexes you have defined

#np.add.at(x, [0,2,3,4], 1) giving i as tuple is also fine
output for this will be as [1. 0. 1. 1. 1. 0. 0. 0. 0. 0.]
Reply


Messages In This Thread
add.at() method - by Truman - May-25-2020, 10:14 PM
RE: add.at() method - by KavyaL - May-26-2020, 04:53 AM
RE: add.at() method - by pyzyx3qwerty - May-26-2020, 09:54 AM
RE: add.at() method - by KavyaL - May-26-2020, 10:56 AM
RE: add.at() method - by Truman - May-26-2020, 09:18 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020