How To Specify The Last Index Explicitly To Np.ufunc.reduceat
Say I have an array data = np.arange(6) I want to find the sum of the entire array and the second half using np.add.reduceat.1 If I do it like this: np.add.reduceat(data, [0, 6, 3
Solution 1:
I haven't used reduceat
much, but it looks like you can only have one open ended range, one add to the end
.
One way around that is to pad the array (yes, I do normally rail against using np.append
:) ):
In [165]: np.add.reduceat(np.append(x,0),[0,6,3])
Out[165]: array([15, 0, 12])
or with a full pairing of ranges:
In [166]: np.add.reduceat(np.append(x,0),[0,6,3,6])
Out[166]: array([15, 0, 12, 0])
I omitted the usual [::2] to clarify what is going on.
Post a Comment for "How To Specify The Last Index Explicitly To Np.ufunc.reduceat"