📜  sciPy stats.relfreq()函数| Python

📅  最后修改于: 2022-05-13 01:55:16.773000             🧑  作者: Mango

sciPy stats.relfreq()函数| Python

scipy.stats.relfreq(a, numbins, defaultreallimits, weights)是一个相对频率直方图,使用 histogram函数。

代码#1:

# relative frequency
from scipy import stats
import numpy as np 
  
arr1 = [1, 3, 27, 2, 5, 13] 
print ("Array element : ", arr1, "\n")
  
a, b, c, d = stats.relfreq(arr1, numbins = 4)
  
print ("cumulative frequency : ", a)
print ("Lower Limit : ", b)
print ("bin size : ", c)
print ("extra-points : ", d)

输出 :

Array element :  [1, 3, 27, 2, 5, 13] 

cumulative frequency :  [0.66666667 0.16666667 0.         0.16666667]
Lower Limit :  -3.333333333333333
bin size :  8.666666666666666
extra-points :  0

代码#2:

# relative frequency
from scipy import stats
import numpy as np 
  
arr1 = [1, 3, 27, 2, 5, 13] 
print ("Array element : ", arr1, "\n")
  
a, b, c, d = stats.relfreq(arr1, numbins = 4,
              weights = [.1, .2, .1, .3, 1, 6])
  
print ("cumfreqs : ", a)
print ("lowlim : ", b)
print ("binsize : ", c)
print ("extrapoints : ", d)

输出 :

Array element :  [1, 3, 27, 2, 5, 13] 

cumfreqs :  [0.26666667 1.         0.         0.01666667]
lowlim :  -3.333333333333333
binsize :  8.666666666666666
extrapoints :  0