回答編集履歴
1
追記
test
CHANGED
@@ -65,3 +65,63 @@
|
|
65
65
|
"""
|
66
66
|
|
67
67
|
```
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
### 参考(pandasを使わない方法)
|
72
|
+
|
73
|
+
pandasに頼りたくない場合、pandasのgroupby相当のものがnumpyにも標準にもないので少し手間取ります。`defaultdict(list)`などを使うと比較的楽で、速度などの懸念もないかと思います。
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
```python
|
78
|
+
|
79
|
+
import numpy as np
|
80
|
+
|
81
|
+
from operator import itemgetter
|
82
|
+
|
83
|
+
from collections import defaultdict
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
out_classes = np.array([0, 0, 3, 3, 5])
|
88
|
+
|
89
|
+
out_scores = np.array([0.99801666, 0.7711145, 0.9962558, 0.96635705, 0.80220133])
|
90
|
+
|
91
|
+
out_boxes = np.array(
|
92
|
+
|
93
|
+
[[ 8.540416, 61.232857, 76.36931, 123.20946 ],
|
94
|
+
|
95
|
+
[ 10.599434, 67.45303, 75.46433, 115.5706 ],
|
96
|
+
|
97
|
+
[101.44424, 137.79492, 165.17267, 201.09848 ],
|
98
|
+
|
99
|
+
[ 90.32121, 60.167862, 160.19128, 126.34792 ],
|
100
|
+
|
101
|
+
[ 92.46553, 210.28862, 167.8457, 296.00696 ]])
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
d = defaultdict(list)
|
106
|
+
|
107
|
+
for i, c in enumerate(out_classes):
|
108
|
+
|
109
|
+
d[c].append((i, out_scores[i]))
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
idx = [max(x, key=itemgetter(1))[0] for c, x in d.items()]
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
# 例示用
|
118
|
+
|
119
|
+
print(d) # defaultdict(<class 'list'>, {0: [(0, 0.99801666), (1, 0.7711145)], 3: [(2, 0.9962558), (3, 0.96635705)], 5: [(4, 0.80220133)]})
|
120
|
+
|
121
|
+
print(idx) # [0, 2, 4]
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
# 以下はidxを用いて取り出すだけで、pandasを用いたコードと同じ
|
126
|
+
|
127
|
+
```
|