I'm looking for a way to multiply the values of a Counter object, i.e.
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})
What's the standard way of doing this in python?
Why I want to do this: I have a sparse feature vector (bag of words represented by a Counter object) that I would like to normalize.
You can do this :
for k in a.keys():
a[k] = a[k] * 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With