Note
Numpy (39) 본문
728x90
How to find the count of unique values in a numpy array?
# Import iris keeping the text column intact
url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data'
iris = np.genfromtxt(url, delimiter=',', dtype='object')
names = ('sepallength', 'sepalwidth', 'petallength', 'petalwidth', 'species')
# Solution
# Extract the species column as an array
species = np.array([row.tolist()[4] for row in iris])
# Get the unique values and the counts
np.unique(species, return_counts=True)
# output
(array([b'Iris-setosa', b'Iris-versicolor', b'Iris-virginica'],
dtype='|S15'), array([50, 50, 50]))
'Numpy' 카테고리의 다른 글
Numpy (41) (0) | 2022.09.04 |
---|---|
Numpy (40) (2) | 2022.09.03 |
Numpy (38) (0) | 2022.08.30 |
Numpy (37) (0) | 2022.08.29 |
Numpy (36) (0) | 2022.08.28 |
Comments