[Numpy-discussion] Proposal for new ufunc functionality
Wed Apr 14 16:48:47 CDT 2010
I would really like to see this become a core part of numpy...
For groupby-like summing over arrays, I use a modified version of
numpy.bincount() which has optional arguments that greatly enhance its
bincount(bin, weights=, max_bins=. out=)
* bins - numpy array of bin numbers (uint8, int16 or int32).
 * Negative bins numbers indicate weights to be ignored
* weights - (opt) numpy array of weights (float or double)
 * max_bin - (opt) bin numbers greater than this are ignored when
* out - (opt) numpy output array (int32 or double)
 This is how I support Robert Kern's comment below "If there are some
areas you want to ignore, that's difficult to do with reduceat()."
 Specifying the number of bins up front has two benefits: (i) saves
scanning the bins array to see how big the output needs to be;
and (ii) allows you to control the size of the output array, as you may
want it bigger than the number of bins would suggest.
I look forward to the draft NEP!
On 13/04/2010 10:34 PM, Robert Kern wrote:
> On Sat, Apr 10, 2010 at 17:59, Robert Kern<email@example.com> wrote:
>> On Sat, Apr 10, 2010 at 12:45, Pauli Virtanen<firstname.lastname@example.org> wrote:
>>> la, 2010-04-10 kello 12:23 -0500, Travis Oliphant kirjoitti:
>>>> Here are my suggested additions to NumPy:
>>>> ufunc methods:
>>>> * reducein (array, indices, axis=0)
>>>> similar to reduce-at, but the indices provide both the
>>>> start and end points (rather than being fence-posts like reduceat).
>>> Is the `reducein` important to have, as compared to `reduceat`?
>> Yes, I think so. If there are some areas you want to ignore, that's
>> difficult to do with reduceat().
> And conversely overlapping areas are highly useful but completely
> impossible to do with reduceat.
More information about the NumPy-Discussion