我这里有一些python代码
代码:
t = 1
xt = array([ -1.,-1. ])
xt[0] = theta[0][0]* P_all_States[t-1][0] + theta[1][0]*P_all_States[t-1][1]
xt[1] = theta[0][1]* P_all_States[t-1][0] + theta[1][1]*P_all_States[t-1][1]
P_all_States[t][0] = xt[0]
P_all_States[t][1] = xt[1]
print ("Added probability distribution for time t = " + str(t) + " to P_all_States")
print P_all_States
输出:
将时间 t = 1 的概率分布添加到 P_all_States [[0.6, 0.4], [0.62000000000000011, 0.38000000000000006], [-1.0, -1.0], [-1.0, -1.0], [-1.0, -1.0], [-1.0 , -1.0]]
如何让浮点数四舍五入到 2 位有效数字?
这些都是浮点数,所以我不想将它们转换为字符串,我希望它们保持为浮点数
谢谢