[Numpy-discussion] exponentiation q.

Keith Goodman kwgoodman@gmail....
Fri Jul 25 15:32:47 CDT 2008


On Fri, Jul 25, 2008 at 1:24 PM, Gideon Simpson <grs2103@columbia.edu> wrote:
> How does python (or numpy/scipy) do exponentiation?  If I do x**p,
> where p is some positive integer, will it compute x*x*...*x (p times),
> or will it use logarithms?

Here are some examples:

>> np.array([[1,2], [3,4]])**2

array([[ 1,  4],
       [ 9, 16]])

>> np.matrix([[1,2], [3,4]])**2

matrix([[ 7, 10],
        [15, 22]])

>> np.power(np.matrix([[1,2], [3,4]]), 2)

matrix([[ 1,  4],
        [ 9, 16]])


More information about the Numpy-discussion mailing list