[英]Python: how to make python calculate a sum to make sure an input is correct?
[英]How do a make sure an arbitrary number of weights sum to 1 (Python)?
我有一个模拟的退火算法,并且有一个类似的函数
result = w1*x1 + w2*x2 + ... + wn*xn
选择新的w
值时,模拟退火的每个循环如何确保w
的总和始终等于1,并且每个w
值都不小于0?
非常感谢大家!
result = np.dot(w, x)
而不是result = w1*x1 + w2*x2 + ... + wn*xn
。 您想要的w
条件似乎可能来自:
non_negative_w = np.abs(w) sum_w = np.sum(non_negative_w) normalized_non_negative_w = non_negative_w / sum_w
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.