![](/img/trans.png)
[英]How can I create a function with a tuple as the parameter and then find the sum of the integers in the tuple without using sum()?
[英]How can I create a array using the random function whose sum is 1 in python using nympy?
處理一項要求我創建一個包含總和為 1 的隨機數的數組的任務。
實際的問題陳述如下所示:
get_initial_weights
This function should have one parameter, an integer m. This function should return a matrix with 1
row and m columns containing random values, each between zero and one. The sum of these m
values should be equal to one.
您可以使用random.random
創建大小為(1,m)
的矩陣,然后將其除以數組的總和以將總和歸一化為 1。
t = np.random.random((1,m))
t = t / t.sum()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.