![](/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.