[Numpy-discussion] fixing diag() for matrices

Sven Schreiber svetosch at gmx.net
Sun Aug 6 14:03:32 CDT 2006


Charles R Harris schrieb:
> Hi Sven,
> 
> On 7/28/06, *Sven Schreiber* <svetosch at gmx.net
> <mailto:svetosch at gmx.net>> wrote:
> 
>     Here's my attempt at summarizing the diag-discussion.
> 
> 
> <snip>
> 
>     2) Deprecate the use of diag which is overloaded with making diagonal
>     matrices as well as getting diagonals. Instead, use the existing
>     .diagonal() for getting a diagonal, and introduce a new make_diag()
>     function which could easily work for numpy-arrays and numpy-matrices
>     alike. 
> 
> 
> This would be my preference, but with functions {get,put}diag. We could
> also add a method or function asdiag, which would always return a
> diagonal matrix made from *all* the elements of the matrix taken in
> order. For (1,n) or (n,1) this would do what you want. For other
> matrices the result would be something new and probably useless, but at
> least it wouldn't hurt.
> 

This seems to have been implemented now by the new diagflat() function.
So, matrix users can now use m.diagonal() for the matrix->vector
direction of diag(), and diagflat(v) for the vector->matrix side of
diag(), and always get numpy-matrix output for numpy-matrix input.

Thanks a lot for making this possible!

One (really minor) comment: "diagflat" as a name is not optimal imho.
Are other suggestions welcome, or is there a compelling reason for this
name?

Thanks,
sven




More information about the Numpy-discussion mailing list