1 term_map tracks which term is in which position.
In [256]: term_map = np.array([2, 2, 3, 4, 4, 4, 2, 0, 0, 0])
In [257]: term_map
Out[257]: array([2, 2, 3, 4, 4, 4, 2, 0, 0, 0])
2 term_scores tracks the weight of each term at each position.
In [258]: term_scores = np.array([5, 6, 9, 8, 9, 4, 5, 1, 2, 1])
In [259]: term_scores
Out[259]: array([5, 6, 9, 8, 9, 4, 5, 1, 2, 1])
3 Get the unique values and the inverse indices.
In [260]: unqID, idx = np.unique(term_map, return_inverse=True)
In [261]: unqID
Out[261]: array([0, 2, 3, 4])
4 Compute the scores for the unique values.
In [262]: value_sums = np.bincount(idx, term_scores)
In [263]: value_sums
Out[263]: array([  4.,  16.,   9.,  21.])
5 Initialize Array To Update. The indices correspond to the values in the term_map variable.
In [254]: vocab = np.zeros(13)
In [255]: vocab
Out[255]: array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])
6 DESIRED: Insert the values 4 corresponding to the positions listed in 3 into the vocab variable.
In [255]: updated_vocab
Out[255]: array([ 4.,  0.,  16.,  9.,  21.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])
How do I create 6?