[SciPy-dev] Idle (?) speculation about ndarray [was draft: NumPy User Guide introduction]

josef.pktd at gmail.com josef.pktd at gmail.com
Fri Aug 21 11:07:12 EDT 2009


On Fri, Aug 21, 2009 at 10:52 AM, David
Goldsmith<d_l_goldsmith at yahoo.com> wrote:
> --- On Thu, 8/20/09, Stéfan van der Walt <stefan at sun.ac.za> wrote:
>
>> I like the idea of an ndarray being a concise description
>> of bytes in
>> memory.  At the moment, we have a couple of "special"
>> methods attached
>> to it, but we could just as well have added fewer or more,
>> and
>> personally I'd have preferred none.
>
> Interesting, I see the appeal from an aesthetics stand point - I don't know enough about such things as: do you think it would have performance implications?  If so, could this be tested by instantiating an ndarray and then assigning None to all of it's attributes (or would you shed only the public methods but not the data attributes, properties, and private accessors on which they rely)?  Just speculating idly at this point.
>

Methods are useful for being overwritten by subclasses. And the last
time I checked method calls were a bit faster than functions.

eg. np.source(np.mean)

    try:
        mean = a.mean
    except AttributeError:
        return _wrapit(a, 'mean', axis, dtype, out)
    return mean(axis, dtype, out)


And, I like methods because they look very good in chaining
(especially with no trailing arguments like in german sentences)

I'm missing absolute value as a method.

mae = (x - a).abs().mean(0)  instead of  mae = np.mean(np.abs(x - a), 0)

Josef

> DG
>
>
>
> _______________________________________________
> Scipy-dev mailing list
> Scipy-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev
>



More information about the SciPy-Dev mailing list