accumulation operation
Executing the following code,
import numpy as np a = np.zeros((3,)) w = np.array([0, 1, 0, 1, 2]) v = np.array([10.0, 1, 10.0, 2, 9]) a[w] += v
I was expecting 'a' to be array([20., 3., 9.]. Instead I get
a array([ 10., 2., 9.])
This with numpy version 1.6.1. Is there another way to do the accumulation I want? Thanks, Ralf
On Wed, 2014-01-22 at 17:23 +0000, Ralf Juengling wrote:
Executing the following code,
import numpy as np
a = np.zeros((3,))
w = np.array([0, 1, 0, 1, 2])
v = np.array([10.0, 1, 10.0, 2, 9])
a[w] += v
I was expecting ‘a’ to be array([20., 3., 9.]. Instead I get
a
array([ 10., 2., 9.])
This with numpy version 1.6.1.
Is there another way to do the accumulation I want?
Since you have addition, you should use np.bincount - Sebastian
Thanks, Ralf
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On 22.01.2014 18:23, Ralf Juengling wrote:
Executing the following code,
import numpy as np
a = np.zeros((3,))
w = np.array([0, 1, 0, 1, 2])
v = np.array([10.0, 1, 10.0, 2, 9])
a[w] += v
I was expecting ‘a’ to be array([20., 3., 9.]. Instead I get
a
array([ 10., 2., 9.])
This with numpy version 1.6.1.
Is there another way to do the accumulation I want?
you want: np.add.at(a, w, v) which is available in numpy 1.8
participants (3)
-
Julian Taylor
-
Ralf Juengling
-
Sebastian Berg