Note
Numpy (43) 본문
728x90
How to get the second largest value of an array when grouped by another 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')
# Solution
# Get the species and petal length columns
petal_len_setosa = iris[iris[:, 4] == b'Iris-setosa', [2]].astype('float')
# Get the second last value
np.unique(np.sort(petal_len_setosa))[-2]
# output
1.7
'Numpy' 카테고리의 다른 글
Numpy (45) (0) | 2022.09.11 |
---|---|
Numpy (44) (0) | 2022.09.10 |
Numpy (42) (0) | 2022.09.06 |
Numpy (41) (0) | 2022.09.04 |
Numpy (40) (2) | 2022.09.03 |
Comments