mindspore.mint.pow

View Source On AtomGit
mindspore.mint.pow(input, exponent)[source]

Calculates the exponent power of each element in input.

When exponent is a Tensor, the shapes of input and exponent must be broadcastable.

\[out_{i} = input_{i} ^{ exponent_{i}}\]

Warning

This is an experimental API that is subject to change or deletion.

Parameters:
  • input (Union[Tensor, Number]) – The first input, which can be a Number or a tensor with data type of number or bool.

  • exponent (Union[Tensor, Number]) –

    The second input, which can be a Number or a tensor with data type of number or bool.

Returns:

Tensor, the shape is the same as the one after broadcasting, and the data type is the one with higher precision or higher digits among the two inputs.

Raises:
  • TypeError – If the types of input and exponent are bool.

  • TypeError – If the input is a tensor and of type int or bool, while the exponent is a negative int.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, mint
>>> input = Tensor(np.array([1.0, 2.0, 4.0]), mindspore.float32)
>>> exponent = 3.0
>>> output = mint.pow(input, exponent)
>>> print(output)
[ 1.  8. 64.]
>>>
>>> input = Tensor(np.array([1.0, 2.0, 4.0]), mindspore.float32)
>>> exponent = Tensor(np.array([2.0, 4.0, 3.0]), mindspore.float32)
>>> output = mint.pow(input, exponent)
>>> print(output)
[ 1. 16. 64.]