Friday, September 26, 2025
HomeLanguagessciPy stats.itemfreq() function | Python

sciPy stats.itemfreq() function | Python

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]

 

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32320 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6683 POSTS0 COMMENTS
Nicole Veronica
11854 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6795 POSTS0 COMMENTS
Ted Musemwa
7071 POSTS0 COMMENTS
Thapelo Manthata
6755 POSTS0 COMMENTS
Umr Jansen
6762 POSTS0 COMMENTS