[Numpy-discussion] matrix problem: float to matrix power
Robert Kern
robert.kern@gmail....
Wed Oct 31 12:34:43 CDT 2007
Charles R Harris wrote:
> On 10/31/07, Robert Kern <robert.kern@gmail.com> wrote:
>> Charles R Harris wrote:
>>> On 10/31/07, Alan G Isaac <aisaac@american.edu> wrote:
>>>>>>> 1.0**numpy.array([1,2,3])
>>>> array([ 1., 1., 1.])
>>>>>>> 1.0**numpy.mat([1,2,3])
>>>> Traceback (most recent call last):
>>>> File "<stdin>", line 1, in <module>
>>>> TypeError: unsupported operand type(s) for ** or pow(): 'float' and 'matrix'
>>>>
>>>> Why the restriction for matrices?
>>> Looks like it just got overlooked. It works fine for 2D arrays.
>>>
>>> In [11]: 1.0**eye(3)
>>> Out[11]:
>>> array([[ 1., 1., 1.],
>>> [ 1., 1., 1.],
>>> [ 1., 1., 1.]])
>> For ndarrays, it does elementwise exponentiation, so it is neither here nor
>> there with respect to matrices. What is the definition of a scalar raised to a
>> matrix power? I don't ever recall seeing one.
>
> I suppose the usual:
>
> a**m = exp(ln(a)*m)
>
> but that isn't the broadcast version.
Ah, yes. Of course. How silly of me.
That raises the question of how to calculate the bloody thing, though. We have
three implementations of expm() in scipy.linalg.matfuncs.
--
Robert Kern
"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
mailing list