[Numpy-discussion] asarray/anyarray; matrix/subclass
Marten van Kerkwijk
m.h.vankerkwijk at gmail.com
Sat Nov 10 12:49:34 EST 2018
I do not think we should change `asanyarray` itself to special-case matrix;
rather, we could start converting `asarray` to `asanyarray` and solve the
problems that produces for matrices in `matrix` itself (e.g., by overriding
the relevant function with `__array_function__`).
I think the idea of providing an `__anyarray__` method (in analogy with
`__array__`) might work. Indeed, the default in `ndarray` (and thus all its
subclasses) could be to let it return `self` and to override it for
`matrix` to return an ndarray view.
All the best,
p.s. Note that we are already giving PendingDeprecationWarning for matrix;
On Sat, Nov 10, 2018 at 11:02 AM Matti Picus <matti.picus at gmail.com> wrote:
> On 9/11/18 5:09 pm, Nathaniel Smith wrote:
> > On Fri, Nov 9, 2018 at 4:59 PM, Stephan Hoyer <shoyer at gmail.com> wrote:
> >> On Fri, Nov 9, 2018 at 6:46 PM Nathaniel Smith <njs at pobox.com> wrote:
> >>> But matrix isn't the only problem with asanyarray. np.ma also violates
> >>> Liskov. No doubt there are other problematic ndarray subclasses out
> >>> there too...
> >>> Please forgive my ignorance (I don't really use mask arrays), but how
> >>> specifically do masked arrays violate Liskov? In most cases shouldn't
> >>> work the same as base numpy arrays, except with operations keeping
> track of
> >>> masks?
> > Since many operations silently skip over masked values, the
> > computation semantics are different. For example, in a regular array,
> > sum()/size() == mean(), but with a masked array these are totally
> > different operations. So if you have code that was written for regular
> > arrays, but pass in a masked array, there's a solid chance that it
> > will silently return nonsensical results.
> > (This is why it's better for NAs to propagate by default.)
> > -n
> Echos of the discussions in neps 12, 24, 25, 26. http://www.numpy.org/neps
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion