# Np.pi equivalent in Pytorch

**URL:** <https://discuss.pytorch.org/t/np-pi-equivalent-in-pytorch/67157>\
**Category:** Uncategorized\
**Created:** [January 20, 2020, 9:39am UTC](https://discuss.pytorch.org/t/np-pi-equivalent-in-pytorch/67157 "2020-01-20T09:39:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![veeresh\_d](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/veeresh_d/32/11043_2.png) [@veeresh\_d](https://discuss.pytorch.org/u/veeresh_d)\
**Post date:** [January 20, 2020, 9:39am UTC](https://discuss.pytorch.org/t/np-pi-equivalent-in-pytorch/67157/1 "2020-01-20T09:39:25Z")

</div>

Hi all,

Could someone tell the [np.pi](https://docs.scipy.org/doc/numpy/reference/constants.html) equivalent in Pytorch? Is there any built-in way to access pi value from torch library? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![LeviViana](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/leviviana/32/9548_2.png) [@LeviViana](https://discuss.pytorch.org/u/LeviViana)\
**Post date:** [January 20, 2020, 2:21pm UTC](https://discuss.pytorch.org/t/np-pi-equivalent-in-pytorch/67157/2 "2020-01-20T14:21:42Z")

</div>

No there isn’t a pretty built-in way.

There are however a lot of ugly ways of doing so. You can, for instance, define `torch.pi` at run-time:

```auto
import torch
torch.pi = torch.acos(torch.zeros(1)).item() * 2 # which is 3.1415927410125732

```

You can even modify the ` __init__.py` file (which is located in `print(torch. __file__ )`) in your environment by adding a line with `pi = 3.14 etc`, so that you will always be able to use the `torch.pi` constant.

---

<div class="post-metadata">

**Author:** ![veeresh\_d](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/veeresh_d/32/11043_2.png) [@veeresh\_d](https://discuss.pytorch.org/u/veeresh_d)\
**Post date:** [January 20, 2020, 8:12pm UTC](https://discuss.pytorch.org/t/np-pi-equivalent-in-pytorch/67157/3 "2020-01-20T20:12:42Z")

</div>

Thank for your response.

---

<div class="post-metadata">

**Author:** ![Alexander\_Soare](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/alexander_soare/32/24720_2.png) [@Alexander\_Soare](https://discuss.pytorch.org/u/Alexander_Soare)\
**Post date:** [June 18, 2021, 9:42am UTC](https://discuss.pytorch.org/t/np-pi-equivalent-in-pytorch/67157/4 "2021-06-18T09:42:36Z")

</div>

Hi! Just stumbled across this. Why would you do this instead of `torch.tensor(math.pi)`. Is it because OP said “built-in”? Is there any other practical advantage to your approach?

---

<div class="post-metadata">

**Author:** ![Grant\_Norman](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/grant_norman/32/55533_2.png) [@Grant\_Norman](https://discuss.pytorch.org/u/Grant_Norman)\
**Post date:** [February 4, 2026, 8:09pm UTC](https://discuss.pytorch.org/t/np-pi-equivalent-in-pytorch/67157/5 "2026-02-04T20:09:05Z")

</div>

Version 2.9.1 (and maybe sooner) includes `torch.pi`, so recent versions do not need to do this anymore.
