[Numpy-discussion] matrix problem: float to matrix power

Charles R Harris charlesr.harris at gmail.com
Wed Oct 31 03:49:49 EDT 2007


On 10/31/07, Alan G Isaac <aisaac at 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.]])

Chuck



More information about the NumPy-Discussion mailing list