<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Feb 10, 2014 at 5:39 PM, Pauli Virtanen <span dir="ltr"><<a href="mailto:pav@iki.fi" target="_blank">pav@iki.fi</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">11.02.2014 01:39, <a href="mailto:josef.pktd@gmail.com">josef.pktd@gmail.com</a> kirjoitti:<br>
[clip]<br>
<div class="">> Almost all the code in scipy.stats and statsmodels starts with np.asarray.<br>
> The numpy doc standard has the term `array_like` to indicate things that<br>
> can be converted to a usable object by ndasarray.<br>
><br>
> ducktyping could be restricted to a very narrow category of ducks.<br>
><br>
> What about masked arrays and structured dtypes?<br>
> Because we cannot usefully convert them by asarray, we have to tell users<br>
> that they don't work with a function.<br>
> Our ducks that quack in the wrong way.?<br>
<br>
</div>The issue here is semantics for basic linear algebra operations, such as<br>
matrix multiplication, that work for different matrix objects, including<br>
ndarrays.<br>
<br>
What is there now in scipy.sparse is influenced by np.matrix, and this<br>
is proving to be sub-optimal, as it is incompatible with ndarrays.<br>
<div class=""><br>
> How do you handle list and other array_likes in sparse?<br>
<br>
</div>if isinstance(t, (list, tuple)): asarray(...)<br>
<br>
Sure, np.matrix can be dealt with as an input too.<br>
<br>
But as said, I'm not arguing so much about asarray'in np.matrices as<br>
input, but the fact that agreement on the meaning of "*" in linear<br>
algebra code in Python is muddled. This should be fixed, and deprecating<br>
np.matrix would point the way.<br>
<br>
(I also suspect that this argument has been raised before, but as long<br>
as there's no canonical write-up...)<br>
<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div><br></div><div>This would require deprecating current sparse as well, no?<br><br></div><div class="h5">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.<br>
<br>Chuck<br></div></div></div></div>