[Numpy-discussion] deprecate numpy.matrix
pav at iki.fi
Mon Feb 10 19:39:16 EST 2014
11.02.2014 01:39, josef.pktd at gmail.com kirjoitti:
> 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
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...)
More information about the NumPy-Discussion