PyTorch .digamma()
Published Aug 5, 2025
Contribute to Docs
In PyTorch, the .digamma() function computes the logarithmic derivative of the gamma function, alternatively known as the digamma function. It is often used in statistical modeling, especially in variational inference and probabilistic programming.
Syntax
torch.digamma(input, *, out=None)
Parameters:
input(Tensor): The input tensor.out(Tensor, optional): The output tensor to store results. Must be the same shape asinput.
Return value:
Returns a tensor containing the result.
Example
This example demonstrates the usage of the .digamma() function:
import torch# Create a tensorx = torch.tensor([1.0, 2.0, 3.0])# Compute the digamma functiony = x.digamma()print(y)
Here is the output:
tensor([-0.5772, 0.4228, 0.9228])
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn PyTorch on Codecademy
- Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.
- Includes 27 Courses
- With Professional Certification
- Beginner Friendly.95 hours
- Learn how to use PyTorch to build, train, and test artificial neural networks in this course.
- Intermediate.3 hours