PyTorch .digamma()

arisdelaCruz1413618857's avatar
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.

  • 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

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 as input.

Return value:

Returns a tensor containing the result.

Example

This example demonstrates the usage of the .digamma() function:

import torch
# Create a tensor
x = torch.tensor([1.0, 2.0, 3.0])
# Compute the digamma function
y = x.digamma()
print(y)

Here is the output:

tensor([-0.5772, 0.4228, 0.9228])

All contributors

Contribute to 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