[Numpy-discussion] subclassing ndarray and keeping same ufunc behavior
nathan12343 at gmail.com
Tue Nov 15 13:52:35 EST 2016
You might also want to consider writing a wrapper object that contains an
ndarray as a (possibly private) attribute and then presents different views
or interpretations of that array.
Subclassing ndarray is a pit of snakes, it's best to avoid it if you can (I
say as the author and maintainer of an ndarray subclass).
On Tue, Nov 15, 2016 at 1:48 PM, Marten van Kerkwijk <
m.h.vankerkwijk at gmail.com> wrote:
> Hi Stuart,
> It certainly seems correct behaviour to return the subclass you
> created: after all, you might want to keep the information on
> `columns` (e.g., consider doing nanmin along a given axis). Indeed, we
> certainly want to keep the unit in astropy's Quantity (which also is a
> subclass of ndarray).
> On the shape: shouldn't that be print(np.nanmin(r).shape)??
> Overall, I think it is worth considering very carefully what exactly
> you try to accomplish; if different elements along a given axis have
> different meaning, I'm not sure it makes all that much sense to treat
> them as a single array (e.g., np.sin might be useful for one column,
> not not another). Even if pandas is slower, the advantage in clarity
> of what is happening might well be more important in the long run.
> All the best,
> p.s. nanmin is not a ufunc; you can find it in numpy/lib/nan_functions.py
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion