Bus errorとSegmentation faultに困ったら見るブログ

物理の研究者による日々の研究生活のメモ書きです ( python/emacs/html/Japascript/シェルスクリプト/TeX/Mac/C言語/Linux/git/tmux/R/ポケモンGO)

【numpy, python3】ヒストグラム(histogram)で最頻値(mode)を取り出したい

hist, bins = np.histogram(input_data, nbin)
delta = (bins[1]-bins[0])/2
xr = np.linspace(np.min(bins)+delta,np.max(bins)-delta,len(bins)-1)
x_max = xr[np.argmax(hist)]
input_data というのがヒストグラムを書くデータ
x_maxが最頻値
ただし、ヒストグラムなので、階段状になっている。ここのx_maxはその階段の真ん中の値になっていると思う

■ 参考 : numpyでヒストグラムの最大地点を取得する関数

ランキング参加中です

↓クリックしていただけると嬉しいです〜