**
is the raise-to-power operator in Python, so x**2
means "x squared" in Python -- including numpy. Such operations in numpy always apply element by element, so x**2
squares each element of array x
(whatever number of dimensions) just like, say, x*2
would double each element, or x+2
would increment each element by two (in each case, x
proper is unaffected -- the result is a new temporary array of the same shape as x
!).
Edit: as @kaizer.ze points out, while what I wrote holds for numpy.array
objects, it doesn't apply to numpy.matrix
objects, where multiplication means matrix multiplication rather than element by element operation like for array
(and similarly for raising to power) -- indeed, that's the key difference between the two types. As the Scipy tutorial puts it, for example:
When we use numpy.array or
numpy.matrix there is a difference.
A*x will be in the latter case matrix
product, not elementwise product as
with array.
i.e., as the numpy reference puts it:
A matrix is a specialized 2-d array
that retains its 2-d nature through
operations. It has certain special
operators, such as *
(matrix
multiplication) and **
(matrix power).