【发布时间】:2014-05-15 12:17:21
【问题描述】:
我正在寻找一种将 Counter 对象的值相乘的方法,即
a = collections.Counter(one=1, two=2, three=3)
>>> Counter({'three': 3, 'two': 2, 'one': 1})
b = a*2
>>> Counter({'three': 6, 'two': 4, 'one': 2})
在 python 中执行此操作的标准方法是什么?
我为什么要这样做: 我有一个稀疏特征向量(由 Counter 对象表示的词袋),我想对其进行规范化。
【问题讨论】:
-
只乘以
2? -
不,有一些真实的因素。我想你会建议使用 +,这将是我的具体情况的解决方案。但是,这对我标准化向量(可能有任何实际长度)的目标没有帮助。
标签: python counter multiplication