On 8 Feb 2015 23:34, "Stefan Reiterer" <domors@gmx.net> wrote:
>
> Ok that are indeed some good reasons to keep the status quo, especially since performance is crucial for numpy.
>  
> It's a dillemma: Using the matrix class for linear algebra would be the correct way for such thing,
> but the matrix API is not that powerful and beautiful as the one of arrays.
> On the other hand arrays are beautiful, but not exactly intended to use for linear algebra.
>  
> So maybe the better way would be not to add warnings to braodcasting operations, but to overhaul the matrix class
> to make it more attractive for numerical linear algebra(?)

The problem here is that as soon as you try to mix code using the matrix class with code using the array class, everything devolves into an unmaintainable mess. And all third party libraries have settled on using the array class, so our long term plan is to get rid of the matrix class entirely -- it's a nice idea but in practice it creates more problems than it solves. (You can look up PEP 465 for some more discussion of this.)

What I think this illustrates is just that textbook linear algebra and computational linear algebra have somewhat different concerns and needs. Textbooks don't have to care about the comparability of APIs across a large system, but that's an absolutely crucial concern when writing code. The obvious analogy is how in textbook linear algebra you just write
  A^{-1} B
but on a computer you had better think about some matrix factorization method instead. Similarly, textbooks generally don't have any formal way to describe flow control and loops, and just write
  A_i = B_i C_i
but in an implementation, looping is often the bulk of the code. Broadcasting provides a powerful notation for describing such loops. (Indeed, it's pretty common to see formal write-ups of algorithms where the the authors either have to resort to painful circumlocutions to describe the data flow, or else just give up and use MATLAB or numpy notation instead of traditional math notation.)

So I think it's incorrect to say that arrays are not designed to be used for linear algebra. They're not designed to be used to write linear algebra *textbooks* -- but they're an extraordinarily well-designed tool for *computational* linear algebra. These are different things and need different tools.

-n