[英]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.