[Numpy-discussion] Regarding Matrices

Travis Oliphant oliphant.travis at ieee.org
Mon Aug 14 17:13:50 EDT 2006


Torgil Svensson wrote:
>>>> import numpy
>>>> numpy.__version__
>>>>         
> '1.0b1'
>   
>>>> from numpy import *
>>>> A = [1,2,3,4,5,6,7,8,9]
>>>> B = asmatrix(reshape(A,(3,3)))
>>>> B
>>>>         
> matrix([[1, 2, 3],
>         [4, 5, 6],
>         [7, 8, 9]])
>   
>>>> B**0
>>>>         
> matrix([[ 1.,  0.,  0.],
>         [ 0.,  1.,  0.],
>         [ 0.,  0.,  1.]])
>   
>>>> power(B,0)
>>>>         
> matrix([[1, 1, 1],
>         [1, 1, 1],
>         [1, 1, 1]])
>
> Shouldn't power() and the ** operator return the same result for matrixes?
>   
No.  power is always the ufunc which does element-by-element raising to 
a power.  This is actually a feature in that you can use the function 
call to do raising to a power without caring what kind of array subclass 
is used.

In the same manner, multiply is *always* the ufunc.


-Travis





More information about the NumPy-Discussion mailing list