Definition der Präzision von floating-point-Zahl in Python

Ich habe einige python-code hier

Code:

 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

Ausgabe:

Hinzugefügt Wahrscheinlichkeitsverteilung zur Zeit t = 1 zu 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]]

Wie bekomme ich die floating-point-zahlen zu Runden 2 sigficant Ziffern?

Diese sind alle Schwimmer, so dass ich nicht suchen, konvertiert diese in strings, möchte ich Ihnen zu bleiben, da schwimmt

Dank

InformationsquelleAutor banditKing | 2012-10-13
Schreibe einen Kommentar