numpy 配列との順序を保持するx
タグのリストがあり、各要素が属するクラスを記録します。たとえば、2 つの異なるクラスとの場合:cls
x
x
0
1
x = [47 21 16 19 38]
cls = [0 0 1 0 1]
一緒に属していることを意味し47, 21, 19
、そうです16, 38
。
クラスごとに要素を選択するpythonicな方法はありますx
か?
今、私はやっています
for clusterId in np.unique(cls):
indices = [i for i in range(len(cls)) if cls[i]==clusterId]
print 'Class ', clusterId
for idx in indices:
print '\t', x[idx,].tolist()
しかし、これほどエレガントなものはないなんて信じられません。