To follow up with an example as to why it is useful that a temporary object
is created, consider the following (taken from the radial reduction
example):

    g = group_by(np.round(radius, 5).flatten())
    pp.errorbar(
        g.unique,
        g.mean(sample.flatten())[1],
        g.std(sample.flatten())[1] / np.sqrt(g.count))

Creating the GroupBy object encapsulates the expense of 'indexing' the
keys, which is the most expensive part of these operations. We would have
to redo that four times here, if we didn't have access to the GroupBy
object.

>From looking at the numpy source, I get the impression that it is
considered good practice not to overuse OOP. And I agree, but I think it is
called for here.


On Sun, Jan 26, 2014 at 6:02 PM, Stéfan van der Walt <ste...@sun.ac.za>wrote:

> Hi Eelco
>
> On Sun, 26 Jan 2014 12:20:04 +0100, Eelco Hoogendoorn wrote:
> > key1 = list('abaabb')
> > key2 = np.random.randint(0,2,(6,2))
> > values = np.random.rand(6,3)
> > print group_by((key1, key2)).median(values)
>
> I agree that group_by functionality could be handy in numpy.
> In the above example, what would the output of
>
> ``group_by((key1, key2))``
>
> be?
>
> Stéfan
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to