May-26-2020, 10:56 AM
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.]
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..