[Numpy-discussion] deprecate numpy.matrix

Matthew Brett matthew.brett at gmail.com
Tue Feb 11 11:25:39 EST 2014


On Tue, Feb 11, 2014 at 4:16 AM, Jacco Hoekstra - LR
<J.M.Hoekstra at tudelft.nl> wrote:
> For our students, the matrix class is really appealing as we use a lot of linear algebra and expressions with matrices simply look better with an operator instead of a function:
>         x=A.I*b
> looks much better than
>         x = np.dot(np.linalg.inv(A),b)

Yes, but:

1)  as Alan has mentioned, the dot method helps a lot.

import numpy.linalg as npl

x = npl.inv(A).dot(b)

2) Overloading the * operator means that you've lost * to do
element-wise operations.  MATLAB has a different operator for that,
'.*' - and it's very easy to forget the dot.  numpy makes this more
explicit - you read 'dot' as 'dot'.

> And this gets worse when the expression is longer:
>         x = R.I*A*R*b
> becomes:
>         x = np.dot( np.linalg.inv(R), np.dot(A, np.dot(R, b)))

x = npl.inv(R).dot(A.dot(R.dot(b))

> Actually, not being involved in earlier discussions on this topic, I was a bit surprised by this and do not see the problem of having the matrix class as nobody is obliged to use it. I tried to find the reasons, but did not find it in the thread mentioned. Maybe someone could summarize the main problem with keeping this class for newbies on this list like me?
> Anyway, I would say that there is a clear use for the matrix class: readability of linear algebra code and hence a lower chance of errors, so higher productivity.

Yes, but it looks like there are not any developers on this list who
write substantial code with the np.matrix class, so, if there is a
gain in productivity, it is short-lived, soon to be replaced by a



More information about the NumPy-Discussion mailing list