Re: [Numpy-discussion] fixing diag() for matrices

2006-08-06 Thread Sven Schreiber
Charles R Harris schrieb: > Hi Sven, > > On 7/28/06, *Sven Schreiber* <[EMAIL PROTECTED] > > wrote: > > Here's my attempt at summarizing the diag-discussion. > > > > > 2) Deprecate the use of diag which is overloaded with making diagonal > matrices as wel

Re: [Numpy-discussion] fixing diag() for matrices

2006-07-29 Thread Charles R Harris
Hi Sven,On 7/28/06, Sven Schreiber <[EMAIL PROTECTED]> wrote: Here's my attempt at summarizing the diag-discussion. 2) Deprecate the use of diag which is overloaded with making diagonalmatrices as well as getting diagonals. Instead, use the existing.diagonal() for getting a diagonal, and introduce

Re: [Numpy-discussion] fixing diag() for matrices

2006-07-28 Thread Alan G Isaac
The following are from pyGAUSS. fwiw, Alan Isaac #diag: diagonal of matrix as column vector (2D only!) def diag(x): if not isinstance(x,numpy.matrix): x = numpy.asanyarray(x) assert(len(x.shape)==2), "For 2-d arrays only." return x.diagonal

Re: [Numpy-discussion] fixing diag() for matrices

2006-07-28 Thread Robert Kern
Sven Schreiber wrote: > The third solution is probably the way of least resistance. However, > afaik this would be the first time that numpy needs different functions > to perform essentially the same operation. Since Robert already cited > the obligatory zen phrase, what about this special casing?

Re: [Numpy-discussion] fixing diag() for matrices

2006-07-28 Thread Sven Schreiber
Here's my attempt at summarizing the diag-discussion. The symptom is that currently transforming something like the vector a b c into the diagonal matrix a 0 0 0 b 0 0 0 c is not directly possible if you're working with numpy-matrices (i.e. the vector is of type matrix and has shape (n,1) or (1,n

Re: [Numpy-discussion] fixing diag() for matrices

2006-07-28 Thread Robert Kern
Christopher Barker wrote: > Keith Goodman wrote: >> diag(NxN matrix) should return a Nx1 matrix >> diag(Nx1 or 1xN matrix) should return a NxN matrix > > This is the key problem: extracting the diagonal of a matrix and > creating a matrix from a diagonal are two different operations: > overloadi

Re: [Numpy-discussion] fixing diag() for matrices

2006-07-28 Thread Christopher Barker
Keith Goodman wrote: > diag(NxN matrix) should return a Nx1 matrix > diag(Nx1 or 1xN matrix) should return a NxN matrix This is the key problem: extracting the diagonal of a matrix and creating a matrix from a diagonal are two different operations: overloading one function to do both was a bad i

Re: [Numpy-discussion] fixing diag() for matrices

2006-07-28 Thread Robert Kern
Sven Schreiber wrote: > Robert Kern schrieb: >> Sven Schreiber wrote: >>> That would be fine with me. However, I'd like to point out that after >>> some bug-squashing currently all numpy functions deal with >>> numpy-matrices correctly, afaik. The current behavior of numpy.diag >>> could be viewed

Re: [Numpy-discussion] fixing diag() for matrices

2006-07-28 Thread Keith Goodman
Every time I want to make a diagonal matrix from a vector I have to do a google search. So I'm with you Sven: diag(NxN matrix) should return a Nx1 matrix diag(Nx1 or 1xN matrix) should return a NxN matrix instead of the current behavior: diag(NxN matrix) returns an array diag(Nx1 matrix) returns

Re: [Numpy-discussion] fixing diag() for matrices

2006-07-28 Thread Sven Schreiber
Robert Kern schrieb: > Sven Schreiber wrote: >> That would be fine with me. However, I'd like to point out that after >> some bug-squashing currently all numpy functions deal with >> numpy-matrices correctly, afaik. The current behavior of numpy.diag >> could be viewed as a violation of that princi

Re: [Numpy-discussion] fixing diag() for matrices

2006-07-27 Thread Robert Kern
Sven Schreiber wrote: > That would be fine with me. However, I'd like to point out that after > some bug-squashing currently all numpy functions deal with > numpy-matrices correctly, afaik. The current behavior of numpy.diag > could be viewed as a violation of that principle. (Because if x has > sh

Re: [Numpy-discussion] fixing diag() for matrices

2006-07-25 Thread Sven Schreiber
Robert Kern schrieb: > Sven Schreiber wrote: >> Hi, >> >> there was a thread about this before, diag() is currently only >> partly useful if you work with numpy-matrices, because the 1d->2d >> direction doesn't work, as there are no 1d-numpy-matrices. This is >> unfortunate because a numpy-matrix w

Re: [Numpy-discussion] fixing diag() for matrices

2006-07-25 Thread Robert Kern
Sven Schreiber wrote: > Hi, > > there was a thread about this before, diag() is currently only > partly useful if you work with numpy-matrices, because the 1d->2d > direction doesn't work, as there are no 1d-numpy-matrices. This is > unfortunate because a numpy-matrix with shape (n,1) or (1,m) sho

[Numpy-discussion] fixing diag() for matrices

2006-07-25 Thread Sven Schreiber
Hi, there was a thread about this before, diag() is currently only partly useful if you work with numpy-matrices, because the 1d->2d direction doesn't work, as there are no 1d-numpy-matrices. This is unfortunate because a numpy-matrix with shape (n,1) or (1,m) should be naturally treated as a vect