Open In App

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

Last Updated : 09 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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

chi-square-distribution

noncentral chi-square distribution

Example:

Python3




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 :

 random.noncentral_chisquare() output plot

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

Python3




# 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

histogram of  random.noncentral_chisquare() output



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads