파이썬 numpy array에서 count하기

허선우·2021년 6월 9일
0

PYTHON

목록 보기
16/17

numpy array는 count함수를 갖지 않는다.
이땐 collections 라이브러리를 사용한다.

예제

import numpy as np
import collections

coin= ['앞면','뒷면']
for _ in range(5):
    case = np.random.choice(coin,8)
    print(collections.Counter(case)['뒷면'])
    # Counter함수/array이름/찾고자하는 요소 이름

0개의 댓글