[Numpy-discussion] fixing diag() for matrices
robert.kern at gmail.com
Fri Jul 28 15:37:55 CDT 2006
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:
> overloading one function to do both was a bad idea to begin with.
> Maybe we should just keep diag() as is is for backward compatibility
> (deprecated), and make:
> get_diag() and make_diag() instead.
> Then it would be unambiguous what you wanted with:
> You can call them something else, but you get the idea.
As .diagonal() is a method on both arrays and matrices, we don't need a separate
In the abstract, I heartily approve. However, I'm not sure that deprecation in
favor of a clumsier name is going to be effective in practice. diag([a, b, c])
is just too tempting and will remain an attractive nuisance. It matches
mathematical notation ever so nicely.
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Numpy-discussion