pow¶
Documentation¶
-
treetensor.torch.
pow
(input, exponent, *args, **kwargs)[source]¶ Takes the power of each element in
input
withexponent
and returns a tensor with the result.Examples:
>>> import torch >>> import treetensor.torch as ttorch >>> ttorch.pow( ... ttorch.tensor([4, 3, 2, 6, 2]), ... ttorch.tensor([4, 2, 6, 4, 3]), ... ) tensor([ 256, 9, 64, 1296, 8]) >>> ttorch.pow( ... ttorch.tensor({ ... 'a': [4, 3, 2, 6, 2], ... 'b': { ... 'x': [[3, 4, 6], ... [6, 3, 5]], ... 'y': [[[3, 5, 5], ... [5, 7, 6]], ... [[4, 6, 5], ... [7, 2, 7]]], ... }, ... }), ... ttorch.tensor({ ... 'a': [4, 2, 6, 4, 3], ... 'b': { ... 'x': [[7, 4, 6], ... [5, 2, 6]], ... 'y': [[[7, 2, 2], ... [2, 3, 2]], ... [[5, 2, 6], ... [7, 3, 4]]], ... }, ... }), ... ) <Tensor 0x7f11b13b6e48> ├── a --> tensor([ 256, 9, 64, 1296, 8]) └── b --> <Tensor 0x7f11b13b6d68> ├── x --> tensor([[ 2187, 256, 46656], │ [ 7776, 9, 15625]]) └── y --> tensor([[[ 2187, 25, 25], [ 25, 343, 36]], [[ 1024, 36, 15625], [823543, 8, 2401]]])
Torch Version Related
This documentation is based on torch.pow in torch v1.10.0+cu102. Its arguments’ arrangements depend on the version of pytorch you installed.
If some arguments listed here are not working properly, please check your pytorch’s version with the following command and find its documentation.
1 | python -c 'import torch;print(torch.__version__)' |
The arguments and keyword arguments supported in torch v1.10.0+cu102 is listed below.
Description From Torch v1.10.0+cu102¶
-
torch.
pow
(input, exponent, *, out=None) → Tensor¶ Takes the power of each element in
input
withexponent
and returns a tensor with the result.exponent
can be either a singlefloat
number or a Tensor with the same number of elements asinput
.When
exponent
is a scalar value, the operation applied is:\[\text{out}_i = x_i ^ \text{exponent}\]When
exponent
is a tensor, the operation applied is:\[\text{out}_i = x_i ^ {\text{exponent}_i}\]When
exponent
is a tensor, the shapes ofinput
andexponent
must be broadcastable.- Args:
input (Tensor): the input tensor. exponent (float or tensor): the exponent value
- Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> a = torch.randn(4) >>> a tensor([ 0.4331, 1.2475, 0.6834, -0.2791]) >>> torch.pow(a, 2) tensor([ 0.1875, 1.5561, 0.4670, 0.0779]) >>> exp = torch.arange(1., 5.) >>> a = torch.arange(1., 5.) >>> a tensor([ 1., 2., 3., 4.]) >>> exp tensor([ 1., 2., 3., 4.]) >>> torch.pow(a, exp) tensor([ 1., 4., 27., 256.])
-
torch.
pow
(self, exponent, *, out=None) → Tensor
self
is a scalarfloat
value, andexponent
is a tensor. The returned tensorout
is of the same shape asexponent
The operation applied is:
\[\text{out}_i = \text{self} ^ {\text{exponent}_i}\]- Args:
self (float): the scalar base value for the power operation exponent (Tensor): the exponent tensor
- Keyword args:
out (Tensor, optional): the output tensor.
Example:
>>> exp = torch.arange(1., 5.) >>> base = 2 >>> torch.pow(base, exp) tensor([ 2., 4., 8., 16.])