Note
Numpy (45) 본문
728x90
How to find the most frequent value in a numpy array?
# Input:
url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data'
iris = np.genfromtxt(url, delimiter=',', dtype='object')
# Solution:
vals, counts = np.unique(iris[:, 2], return_counts=True)
print(vals[np.argmax(counts)])
# output
b'1.5'
'Numpy' 카테고리의 다른 글
Numpy (47) (0) | 2022.09.13 |
---|---|
Numpy (46) (0) | 2022.09.12 |
Numpy (44) (0) | 2022.09.10 |
Numpy (43) (0) | 2022.09.07 |
Numpy (42) (0) | 2022.09.06 |
Comments