Skip to content

Commit 645c9a9

Browse files
authored
Added term for .pow() in pytorch. (#7929)
* Added term for `.pow()` in pytorch. * Update pow.md ---------
1 parent 89a9d6d commit 645c9a9

File tree

1 file changed

+57
-0
lines changed
  • content/pytorch/concepts/tensor-operations/terms/pow

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
Title: '.pow()'
3+
Description: 'Raises each element of the input tensor to the specified power and returns a new tensor with the computed values.'
4+
Subjects:
5+
- 'Code Foundations'
6+
- 'Computer Science'
7+
- 'Data Science'
8+
Tags:
9+
- 'Arrays'
10+
- 'Elements'
11+
- 'Methods'
12+
- 'PyTorch'
13+
CatalogContent:
14+
- 'learn-python-3'
15+
- 'paths/data-science'
16+
---
17+
18+
The **`.pow()`** method in PyTorch computes the power of each [tensor](https://www.codecademy.com/resources/docs/pytorch/tensors) element by raising it to a specified exponent.
19+
20+
## Syntax
21+
22+
```pseudo
23+
torch.pow(input, exponent, *, out=None)
24+
```
25+
26+
**Parameters:**
27+
28+
- `input`: The input tensor whose elements are to be raised to a power.
29+
- `exponent`: The exponent value(s). If a tensor, it must be broadcastable to the shape of `input`.
30+
- `out` (Optional): A tensor to store the output. If provided, it must have the same shape as `input`.
31+
32+
**Return value:**
33+
34+
Returns a new tensor containing the element-wise results of raising each input element to the specified power.
35+
36+
## Example
37+
38+
The following example demonstrates the usage of the `.pow()` function:
39+
40+
```py
41+
import torch
42+
43+
# Define a tensor
44+
input_tensor = torch.tensor([1.0, 0.5, 3.0, 5.5, 11.0])
45+
46+
# Compute the exponent of each element in the input tensor
47+
output_tensor = torch.pow(input_tensor, 3)
48+
49+
# Print the resultant tensor
50+
print(output_tensor)
51+
```
52+
53+
The above code produces the following output:
54+
55+
```shell
56+
tensor([1.0000e+00, 1.2500e-01, 2.7000e+01, 1.6638e+02, 1.3310e+03])
57+
```

0 commit comments

Comments
 (0)