私は2つの派手な配列を持っていusers
ますdat
. ユーザーごとusers
に、ユーザーに関連するデータを見つけて、dat
一意の値の数をカウントする必要があります。と のケースを処理する必要がlen(users)=200000
ありlen(dat)=2800000
ます。現在、ソートされているという事実を利用していないdat
ため、メソッドが非常に遅くなります。どうすればいいですか?
値 'other'dat
は、他の値が構造化配列にも存在することを示しているだけです。
import numpy as np
users = np.array([111, 222, 333])
info = np.zeros(len(users))
dt = [('id', np.int32), ('group', np.int16), ('other', np.float)]
dat = np.array([(111, 1, 0.0), (111, 3, 0.0), (111, 2, 0.0), (111, 1, 0.0),
(222, 1, 0.0), (222, 1, 0.0), (222, 4, 0.0),
(333, 2, 0.0), (333, 1, 0.0), (333, 2, 0.0)],
dtype=dt)
for i, u in enumerate(users):
u_dat = dat[np.in1d(dat['id'], u)]
uniq = set(u_dat['group'])
info[i] = int(len(uniq))
print info