What does matrix**2 mean in python/numpy?

numpy, python

Solution

It's just the square of each element.

from numpy import *
a = arange(4).reshape((2,2))
print a**2

prints

[[0 1]
 [4 9]]

Problem

I have a python ndarray temp in some code I'm reading that suffers this: ``` x = temp**2 ``` Is this the dot square (ie, equivalent to m.*m) or the matrix square (ie m must be a square matrix)? In particular, I'd like to know whether I can get rid of the transpose in this code: ``` temp = num.transpose(whatever) num.sum(temp**2,axis=1)) ``` and turn it into this: ``` num.sum(whatever**2,axis=0) ``` That will save me at least 0.1ms, and is clearly worth my time. Thanks! The ** operator is ungooglable and I know nothing! a

Original source