[SciPy-dev] I can't find howto get exp(x) or a^x in NumPy_for_Matlab_Users page

Anne Archibald peridot.faceted at gmail.com
Thu Jun 28 11:33:51 EDT 2007


On 28/06/07, Robert Kern <robert.kern at gmail.com> wrote:
> Anne Archibald wrote:
> > On 28/06/07, Matthieu Brucher <matthieu.brucher at gmail.com> wrote:
> >
> >> numpy.exp for a element-wise exponentiation, and a**x for a^x
> >
> > To expand on this: if M is a matrix (not array), then M**3 will
> > compute the cube of the matrix (fairly efficiently). But this will not
> > handle fractional exponents (I'm not totally sure those are
> > well-defined anyway) and I don't know if there is a matrix exponential
> > in numpy.
>
> scipy.linalg has expm, expm2, and expm3 which do the matrix exponential by Padé
> approximation, eigenvalues, and Taylor series, respectively.

It might be worth mentioning in the docstrings that they do not give
the same answer:
In [18]: scipy.linalg.expm(matrix([[1,1],[0,1]]))
Out[18]:
array([[ 2.71828183,  2.71828183],
       [ 0.        ,  2.71828183]])

In [19]: scipy.linalg.expm2(matrix([[1,1],[0,1]]))
Out[19]:
array([[ 2.71828183,  0.        ],
       [ 0.        ,  2.71828183]])

In [20]: scipy.linalg.expm3(matrix([[1,1],[0,1]]))
Out[20]:
array([[ 2.71828183,  2.71828183],
       [ 0.        ,  2.71828183]])

In particular, expm2 silently gives the wrong answer if the matrix is
not diagonalizable.
In [22]: scipy.__version__
Out[22]: '0.5.2'

Anne


More information about the SciPy-Dev mailing list