Skip to content
Related Articles

Related Articles

numpy.random.chisquare() in Python

Improve Article
Save Article
  • Last Updated : 15 Jul, 2020
Improve Article
Save Article

With the help of chisquare() method, we can get chi-square distribution by using this method. Mainly we can use this distribution in hypothesis testing.

chi-square distribution

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

Parameters : 

1) df – number of degree of freedom and must be >0.

2) size – Output shape of scalar array.

Return : Return the scalar numpy array.

Example #1 :

In this example we can see that by using chisquare() method, we are able to get the chi-square distribution and return the scalar numpy array by using this method.

Python3




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

Output :

Example #2 :

Python3




# import chisquare
import numpy as np
import matplotlib.pyplot as plt
  
# Using chisquare() method
gfg = np.random.chisquare(5, 10000)
gfg1 = np.random.chisquare(gfg, 10000)
  
count, bins, ignored = plt.hist(gfg1, 30, density = True)
plt.show()

Output :


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!