sciPy stats.itemfreq()函数| Python
scipy.stats.itemfreq(arr, axis = None)函数帮助我们计算项目频率。
Parameters :
arr : [array_like] input array.
Results : 2D array with item frequency.
代码 #1:使用变体()
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))
输出:
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]