term_map
跟踪哪个术语处于哪个位置。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])
term_scores
跟踪每个项在每个位置的权重。In [260]: unqID, idx = np.unique(term_map, return_inverse=True)
In [261]: unqID
Out[261]: array([0, 2, 3, 4])
In [262]: value_sums = np.bincount(idx, term_scores)
In [263]: value_sums
Out[263]: array([ 4., 16., 9., 21.])
term_map
变量中的值。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.])
vocab
变量。In [255]: updated_vocab
Out[255]: array([ 4., 0., 16., 9., 21., 0., 0., 0., 0., 0., 0., 0., 0.])
如何创建6?在
输出:
[ 4. 0. 16. 9. 21. 0. 0. 0. 0. 0. 0. 0. 0.]
事实证明,我们可以通过输入}步骤直接获得所需的输出,并且还可以使用可选参数
term_map
和term_scores
来避免{minlength
提到输出数组的长度。在因此,我们可以简单地做-
样本运行-
^{pr2}$相关问题 更多 >
编程相关推荐