diff --git a/gensim/matutils.py b/gensim/matutils.py index 6cc8c80133..4c92be4562 100644 --- a/gensim/matutils.py +++ b/gensim/matutils.py @@ -326,7 +326,7 @@ def ret_normalized_vec(vec, length): else: return list(vec) -def ret_log_normalize_vec(vec, axis = 1): +def ret_log_normalize_vec(vec, axis=1): log_max = 100.0 if len(vec.shape) == 1: max_val = numpy.max(vec) @@ -335,17 +335,17 @@ def ret_log_normalize_vec(vec, axis = 1): log_norm = numpy.log(tot) - log_shift vec = vec - log_norm else: - if axis == 1:#independently normalize each sample + if axis == 1: # independently normalize each sample max_val = numpy.max(vec, 1) log_shift = log_max - numpy.log(vec.shape[1] + 1.0) - max_val tot = numpy.sum(numpy.exp(vec + log_shift[:, numpy.newaxis]), 1) log_norm = numpy.log(tot) - log_shift vec = vec - log_norm[:, numpy.newaxis] - elif axis == 0:#normalize each feature + elif axis == 0: # normalize each feature k = ret_log_normalize_vec(vec.T) return (k[0].T, k[1]) else: - raise ValueError("'%d' is not a supported axis" % axis) + raise ValueError("'%s' is not a supported axis" % axis) return (vec, log_norm)