Open In App

NumPy random.noncentral_chisquare() | Draw Samples From Noncentral chisqaure

The NumPy random.noncentral_chisquare() method returns samples from a noncentral chisquare distribution.

noncentral chi-square distribution

Example:




import matplotlib.pyplot as plt
import numpy as np
gfg = np.random.noncentral_chisquare(1.21, 9.89, 1000)
count, bins, ignored = plt.hist(gfg, 30, density = True)
plt.show()

Output :



Syntax

Syntax: numpy.random.noncentral_chisquare(df, nonc, size=None)



Parameters

  • df: Degrees of freedom, must be > 0
  • nonc: Non-centrality, must be non-negative
  • size: Output shape.

Return: Return the random samples as NumPy array.

How to Generate Samples from Noncentral chi-Square Distribution

To generate random samples from a noncentral chi-square distribution we use random.noncentral_chisquare() method of the NumPy library.

Let us understand it better with an example:

Example




# import numpy
import numpy as np
import matplotlib.pyplot as plt
  
# Using noncentral_chisquare() method
gfg = np.random.noncentral_chisquare(14.05, 3.24, 3000)
  
count, bins, ignored = plt.hist(gfg, 14, density = True)
plt.show()

Output


Article Tags :