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()

filter_none

edit
close

play_arrow

link
brightness_4
code

# cummulative 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))

chevron_right


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

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.