Open In App

NumPy random.noncentral_f() | Get Random Samples from noncentral F distribution

Improve
Improve
Like Article
Like
Save
Share
Report

The NumPy random.noncentral_f() method returns the random samples from the noncentral F distribution.

Example

Python3




import numpy as np
import matplotlib.pyplot as plt
gfg = np.random.noncentral_f(1.24, 21, 3, 1000)
count, bins, ignored = plt.hist(gfg, 50, density = True)
plt.show()


Output:

graph of random samples generated by random.noncentral_f()

Syntax

Syntax: numpy.random.noncentral_f(dfnum, dfden, nonc, size=None)

Parameters:

  • dfnum: Degrees of freedom in numerator.
  • dfden: Degrees of freedom in denominator.
  • nonc: Non-centrality parameter.
  • size: Output shape.

Return: Return the random samples as numpy array.

How to Generate Random Samples from a noncentral F Distribution

To generate random samples from a noncentral F distribution we use the random.noncentral_f() method of NumPy library.

We have explained the method in the example below by plotting histogram using Matplot library.

Python3




# import numpy
import numpy as np
import matplotlib.pyplot as plt
  
# Using noncentral_f() method
gfg = np.random.noncentral_f(10.23, 12.13, 3, 10000)
  
count, bins, ignored = plt.hist(gfg, 14, density = True)
plt.show()


Output:

random.noncentral_f() method histogram with matplotlib



Last Updated : 09 Feb, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads