Python Scipy stats.halfgennorm.pdf() Function

Scipy Library in Python:

  • SciPy is a scientific computation package that uses the NumPy library underneath.
  • SciPy is an abbreviation for Scientific Python.
  • It includes additional utility functions for optimization, statistics, and signal processing.
  • SciPy, like NumPy, is open source, so we can freely use it.
  • Travis Olliphant, the developer of NumPy, created SciPy.
  • SciPy has optimized and added/enhanced functions that are often used in NumPy and Data Science.

stats.halfgennorm.pdf() Function:

We can obtain the value of the probability density function by using the stats.halfgennorm.pdf() method.

The formula of probability density function for halfgennorm:

Formula of probability density function for halfgennorm

Syntax:

stats.halfgennorm.pdf(x, beta)

Return Value:

The probability density value is returned by the stats.halfgennorm.pdf() Function.

Scipy stats.halfgennorm.pdf() Function in Python

Method #1: Using pdf() Function (Static Input)

Approach:

  •  Import halfgennorm() method from stats of scipy module using the import keyword
  • Give the beta value as static input and store it in a variable.
  • Calculate the probability density value using the pdf() function of halfgennorm by passing some random value(x), given beta value as arguments to it.
  • Store it in another variable.
  • Print the probability density value for the given beta value.
  • The Exit of the Program.

Below is the implementation:

# Import halfgennorm() method from stats of scipy module using the import keyword
from scipy.stats import halfgennorm

# Give the beta value as static input and store it in a variable.
gvn_beta = 2

# Calculate the probability density value using the pdf() function of halfgennorm by passing
# some random value(x), given beta value as arguments to it.
# Store it in another variable.
rslt = halfgennorm.pdf(0.2, gvn_beta)

# Print the probability density value for the given beta value
print("The probability density value for the given beta {", gvn_beta,"} value = ", rslt)

Output:

The probability density value for the given beta { 2 } value = 1.0841347871048632

Method #2: Using pdf() Function (User Input)

Approach:

  •  Import halfgennorm() method from stats of scipy module using the import keyword
  • Give the beta value as user input using the int(input()) function and store it in a variable.
  • Calculate the probability density value using the pdf() function of halfgennorm by passing some random value(x), given beta value as arguments to it.
  • Store it in another variable.
  • Print the probability density value for the given beta value.
  • The Exit of the Program.

Below is the implementation:

# Import halfgennorm() method from stats of scipy module using the import keyword
from scipy.stats import halfgennorm

# Give the beta value as user input using the int(input()) function and store it in a variable.
gvn_beta = int(input("Enter some random number = "))

# Calculate the probability density value using the pdf() function of halfgennorm by passing
# some random value(x), given beta value as arguments to it.
# Store it in another variable.
rslt = halfgennorm.pdf(0.5, gvn_beta)

# Print the probability density value for the given beta value
print("The probability density value for the given beta {", gvn_beta,"} value = ", rslt)

Output:

Enter some random number = 6
The probability density value for the given beta { 6 } value = 1.0612007331497644