Show koos808Python Python Numpy Function Part2 - 파이썬 넘파이 함수koos808 2020. 11. 14. 01:40
numpy array는 count함수를 갖지 않는다. 예제
👀 배열 원소 수 세는 방법 ( count() / collections.Counter() ) 👀 파이썬에서 배열 내원소의 갯수를 세는 방법으로는 다음과 같이 2개의 방법이 존재합니다. collections 모듈의 Counter() 클래스와, 리스트 자체의 count() 함수가 있습니다. 1. count() -> list.count(x)
2. collections.Counter() -> counter = Counter(변수)
count() 함수는 배열에 대해 특정 원소의 갯수만을 추출할 때 사용한다고 보면 되고, collections.Counter()는 모든 원소의 갯수를 셀 때 도움이 됩니다. 목적에 따라 다르게 사용하면 될 것 같습니다.😊 (다만 collections.Counter()는 더욱 다양한 함수들이 있으니, 잘 확인하고 사용하면 많은 도움이 될 것 같습니다.) <참고> docs.python.org/ko/3/library/array.html?highlight=count#array.array.count docs.python.org/ko/3/library/collections.html?highlight=collections#collections.Counter |