# mxnet.ndarray.power¶

mxnet.ndarray.power(base, exp)[source]

Returns result of first array elements raised to powers from second array, element-wise with broadcasting.

Equivalent to base ** exp and mx.nd.broadcast_power(lhs, rhs).

Note

If the corresponding dimensions of two arrays have the same size or one of them has size 1, then the arrays are broadcastable to a common shape.

Parameters
• base (scalar or NDArray) – The base array

• exp (scalar or NDArray) – The exponent array. If base.shape != exp.shape, they must be broadcastable to a common shape.

Returns

The bases in x raised to the exponents in y.

Return type

NDArray

Examples

>>> x = mx.nd.ones((2,3))*2
>>> y = mx.nd.arange(1,3).reshape((2,1))
>>> z = mx.nd.arange(1,3).reshape((2,1))
>>> x.asnumpy()
array([[ 2.,  2.,  2.],
[ 2.,  2.,  2.]], dtype=float32)
>>> y.asnumpy()
array([[ 1.],
[ 2.]], dtype=float32)
>>> z.asnumpy()
array([[ 1.],
[ 2.]], dtype=float32)
>>> (x**2).asnumpy()
array([[ 4.,  4.,  4.],
[ 4.,  4.,  4.]], dtype=float32)
>>> (x**y).asnumpy()
array([[ 2.,  2.,  2.],
[ 4.,  4.,  4.]], dtype=float32)
>>> mx.nd.power(x,y).asnumpy()
array([[ 2.,  2.,  2.],
[ 4.,  4.,  4.]], dtype=float32)
>>> (z**y).asnumpy()
array([[ 1.],
[ 4.]], dtype=float32)