|
| 1 | +--- |
| 2 | +Title: '.i0()' |
| 3 | +Description: 'Computes the modified Bessel function of the first kind of order zero.' |
| 4 | +Subjects: |
| 5 | + - 'AI' |
| 6 | + - 'Data Science' |
| 7 | + - 'Machine Learning' |
| 8 | +Tags: |
| 9 | + - 'AI' |
| 10 | + - 'Deep Learning' |
| 11 | + - 'Functions' |
| 12 | + - 'Machine Learning' |
| 13 | + - 'PyTorch' |
| 14 | +CatalogContent: |
| 15 | + - 'intro-to-py-torch-and-neural-networks' |
| 16 | + - 'paths/computer-science' |
| 17 | +--- |
| 18 | + |
| 19 | +In PyTorch, the **`.i0()`** function (an alias of `torch.special.i0()`) computes the modified Bessel function of the first kind of order zero (I₀). This function is commonly used in signal processing, physics simulations, and statistical distributions such as the von Mises distribution for circular data. |
| 20 | + |
| 21 | +## Syntax |
| 22 | + |
| 23 | +```pseudo |
| 24 | +torch.i0(input, *, out=None) |
| 25 | +``` |
| 26 | + |
| 27 | +Or, alternatively: |
| 28 | + |
| 29 | +```pseudo |
| 30 | +torch.special.i0(input, *, out=None) |
| 31 | +``` |
| 32 | + |
| 33 | +**Parameters:** |
| 34 | + |
| 35 | +- `input` (Tensor): The input tensor whose elements are the values at which to compute the modified Bessel function I₀. |
| 36 | +- `out` (Tensor, optional): The output tensor to store the result. |
| 37 | + |
| 38 | +**Return value:** |
| 39 | + |
| 40 | +Returns a tensor containing the computed modified Bessel function of the first kind, order zero (I₀), for each element of the input tensor. |
| 41 | + |
| 42 | +## Example |
| 43 | + |
| 44 | +In this example, `torch.i0()` calculates the modified Bessel function I₀ for each element in a 1D tensor: |
| 45 | + |
| 46 | +```py |
| 47 | +import torch |
| 48 | + |
| 49 | +# Create input tensor |
| 50 | +x = torch.tensor([0.0, 1.0, 2.0, 3.0, 4.0]) |
| 51 | + |
| 52 | +# Compute the modified Bessel function |
| 53 | +result = torch.i0(x) |
| 54 | + |
| 55 | +print("Input values:", x) |
| 56 | +print("I₀(x) values:", result) |
| 57 | +``` |
| 58 | + |
| 59 | +The above code produces the following output: |
| 60 | + |
| 61 | +```shell |
| 62 | +Input values: tensor([0., 1., 2., 3., 4.]) |
| 63 | +I₀(x) values: tensor([1.0000, 1.2661, 2.2796, 4.8808, 11.3019]) |
| 64 | +``` |
0 commit comments