Skip to content
Related Articles

Related Articles

sciPy stats.itemfreq() function | Python

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 15 Jan, 2022

scipy.stats.itemfreq(arr, axis = None) function helps us to calculate the item frequencies. 

Parameters : 
arr : [array_like] input array. 
Results : 2D array with item frequency. 

Code #1: Use of variation()  

Python3




# cumulative frequency
from scipy import stats
import numpy as np 
   
arr = [14, 31, 27, 27, 31, 13, 14, 13
   
print ("Itemfrequency : \n", stats.itemfreq(arr))
   
print ("\n\nBincount : \n", np.bincount(arr))

Output: 

Itemfrequency : 
 [[13  2]
 [14  2]
 [27  2]
 [31  2]]


Bincount : 
 [0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 2]

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!