整数値でできた1次元arrayの最頻値を求める際に少してこずってわかりにくかったのでメモ
array = [0,1,1,5]
count = np.bincount(array) -> [1,2,0,0,0,1]
ans = np.argmax(count) -> 1
np.bincountが上の例だと0が1個、1が2個、2~4が0個、5が1個なので上記のような結果を返してくれる。
要素が整数の場合にしか使えないのが難点か
Go to list of users who liked
More than 5 years have passed since last update.
整数値でできた1次元arrayの最頻値を求める際に少してこずってわかりにくかったのでメモ
array = [0,1,1,5]
count = np.bincount(array) -> [1,2,0,0,0,1]
ans = np.argmax(count) -> 1
np.bincountが上の例だと0が1個、1が2個、2~4が0個、5が1個なので上記のような結果を返してくれる。
要素が整数の場合にしか使えないのが難点か
Register as a new user and use Qiita more conveniently
Go to list of users who liked