I would like to use bincount
to sum arrays, however it supports only doubles.
For example this works:
np.bincount([1, 1, 0],weights=np.array([1, 2, 4]))
Out: array([ 4., 3.])
However I would like to use a dimension 2 array as:
np.bincount([1, 1, 0],weights=np.array([[1,1], [2,2], [4,4]]))
ValueError: object too deep for desired array
The desired output is:
Out: array([[ 4., 4.],[3., 3.]])
Better explanation after comments:
I want to sum each row of the array into the corresponding index.
With a loop it would be:
Bin=np.zeros(2,2)
for i in [1,1,0]:
Bin[i]+=a[i]
a is previous 3x2 matrix Есть ли эффективный способ получить этот результат?