def build_bins(self, questions):
"""
returns a dictionary
key: document length (rounded to the powers of two)
value: indexes of questions with document length equal to key
"""
# round the input to the nearest power of two
round_to_power = lambda x: 2**(int(np.log2(x-1))+1)
doc_len = map(lambda x:round_to_power(len(x[0])), questions)
bins = {}
for i, l in enumerate(doc_len):
if l not in bins:
bins[l] = []
bins[l].append(i)
return bins
评论列表
文章目录