[Numpy-discussion] deprecate numpy.matrix

Charles R Harris charlesr.harris at gmail.com
Mon Feb 10 20:11:40 EST 2014

On Mon, Feb 10, 2014 at 5:39 PM, Pauli Virtanen <pav at iki.fi> wrote:

> 11.02.2014 01:39, josef.pktd at gmail.com kirjoitti:
> [clip]
> > Almost all the code in scipy.stats and statsmodels starts with
> np.asarray.
> > The numpy doc standard has the term `array_like` to indicate things that
> > can be converted to a usable object by ndasarray.
> >
> > ducktyping could be restricted to a very narrow category of ducks.
> >
> > What about masked arrays and structured dtypes?
> > Because we cannot usefully convert them by asarray, we have to tell users
> > that they don't work with a function.
> > Our ducks that quack in the wrong way.?
> The issue here is semantics for basic linear algebra operations, such as
> matrix multiplication, that work for different matrix objects, including
> ndarrays.
> What is there now in scipy.sparse is influenced by np.matrix, and this
> is proving to be sub-optimal, as it is incompatible with ndarrays.
> > How do you handle list and other array_likes in sparse?
> if isinstance(t, (list, tuple)): asarray(...)
> Sure, np.matrix can be dealt with as an input too.
> But as said, I'm not arguing so much about asarray'in np.matrices as
> input, but the fact that agreement on the meaning of "*" in linear
> algebra code in Python is muddled. This should be fixed, and deprecating
> np.matrix would point the way.
> (I also suspect that this argument has been raised before, but as long
> as there's no canonical write-up...)
This would require deprecating current sparse as well, no?

I could be convinced to follow this route if there were a pedagogic version
of a matrix type that was restricted to linear algebra available as a
separate project. It could even have some improvements, row and column
vectors, inv, etc, but would not be as full featured as numpy arrays. The
idea is that it would serve for teaching matrices rather than numerical
programming in python.  Hopefully that would satisfy Alan's teaching use
case. There is the danger of students getting tied to that restricted
implementation, but that may not be something to worry about for the sort
of students Alan is talking about.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140210/49f7185b/attachment.html>

More information about the NumPy-Discussion mailing list