[SciPy-user] why does linalg.sqrtm return an array?
Thu Oct 9 18:34:40 CDT 2008
On Thu, Oct 9, 2008 at 13:26, Brian Blais <firstname.lastname@example.org> wrote:
> I was just bitten by the fact that sqrtm returns an array, not a matrix.
> Every time I tried to test it with Q*Q, or Q.T*Q I got very strange results
> (I was just about to post that it was seriously broken). Then I found out
> that it returns an array! Why is that? It would seem that if you are doing
> a matrix square root, you are working with matrices mostly in that
> calculation, so a matrix is the consistent thing to return (and perhaps the
> least surprising thing to return). Is there a reason for this?
Arguably, it should return a matrix object if given a matrix object,
but it should never return a matrix object if given a pure ndarray.
Just because one is doing matrix operations doesn't mean one wants to
use matrix objects.
But the fact that it returns an ndarray when given a matrix object is
a bug, and you're welcome to fix it. It's not always easy to do,
though, so you will find many such functions which do not preserve the
type of the input(s).
"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 SciPy-user