print(np.bincount(np.array([0, 1, 1, 3, 2, 1, 7])))
Z = np.ones(10)
l = len(Z)
print(l)
I = np.random.randint(0,l,20)
print(I)
B = np.bincount(I, minlength=20)
print(B)
B = np.bincount(I, minlength=l)
print(B)
X = Z + B
print("====X====")
print(X)
# Another solution
# Author: Bartosz Telenczuk
np.add.at(Z, I, 1)
print(Z)
- e.g.
[1 3 1 1 0 0 0 1]
10
[6 6 9 5 6 4 5 4 2 8 1 9 0 2 8 7 0 2 9 2]
[2 1 4 0 2 2 3 1 2 3 0 0 0 0 0 0 0 0 0 0]
[2 1 4 0 2 2 3 1 2 3]
====X====
[ 3. 2. 5. 1. 3. 3. 4. 2. 3. 4.]
[ 3. 2. 5. 1. 3. 3. 4. 2. 3. 4.]