Python Scipy stats.halfgennorm.stats() 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.

Scipy stats.halfgennorm.stats() Function

We can obtain the value of Mean(‘m’), variance(‘v’), skew (‘s’), and/or kurtosis(‘k’) by using the stats.halfgennorm.stats() function.

Syntax:

 stats.halfgennorm.stats(beta, moments)

Return Value:

The value of mean, variance, skew, and kurtosis is returned by the stats() function.

Scipy stats.halfgennorm.stats() Function in Python

Method #1: Using stats() 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.
  • Pass the given beta value, moments =’mvsk’ as arguments to the stats() function of halfgennorm module to get the values of Mean, Variance, Skew, kurtosis for the given beta value.
  • Store them in 4 separate variables
  • Print the values of Mean, Variance, Skew, kurtosis 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 = 3

# Pass the given beta value, moments ='mvsk' as arguments to the stats() function of 
# halfgennorm module to get the values of Mean, Variance, Skew, kurtosis for the given beta value.
# Store them in 4 separate variables 
Mean, Variance, Skew, kurtosis = halfgennorm.stats(gvn_beta, moments ='mvsk')
# Print the values of Mean, Variance, Skew, kurtosis for the given beta value
print("The values of Mean, Variance, Skew, kurtosis for the given beta{",gvn_beta,"} value:")
print(Mean, Variance, Skew, kurtosis)

Output:

The values of Mean, Variance, Skew, kurtosis for the given beta{ 3 } value:
0.5054680881515111 0.1177841857623046 0.6327758514663764 -0.15848408785769097

Method #2: Using stats() 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.
  • Pass the given beta value, moments =’mvsk’ as arguments to the stats() function of halfgennorm module to get the values of Mean, Variance, Skew, kurtosis for the given beta value.
  • Store them in 4 separate variables
  • Print the values of Mean, Variance, Skew, and kurtosis 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 = "))

# Pass the given beta value, moments ='mvsk' as arguments to the stats() function of 
# halfgennorm module to get the values of Mean, Variance, Skew, kurtosis for the given beta value.
# Store them in 4 separate variables 
Mean, Variance, Skew, kurtosis = halfgennorm.stats(gvn_beta, moments ='mvsk')
# Print the values of Mean, Variance, Skew, kurtosis for the given beta value
print("The values of Mean, Variance, Skew, kurtosis for the given beta{",gvn_beta,"} value:")
print(Mean, Variance, Skew, kurtosis)

Output:

Enter some random number = 2
The values of Mean, Variance, Skew, kurtosis for the given beta{ 2 } value:
0.5641895835415295 0.1816901138291821 0.9952717461750911 0.8691773035274091