How to stop getting zeros returned in python? -
this question has answer here:
- python division 10 answers
hi there trying values simple fractions 1/225 or 35/75 keeps returning zeros? appreciated!
mymatrix=[[0,1,1],[1,0,1],[1,1,0]] uu=len(mymatrix) initials_ss=[[150],[300],[100]] #your initial population size suceptibles initials_zz=[[5],[15],[555]] #your initial population size zombies initials_rr=[[0],[0],[0]] #your initial population size removed s_n=np.matrix(initials_ss) #initial value suceptibles vector z_n=np.matrix(initials_zz) #initial value zombie vector r_n=np.matrix(initials_rr) #initial value removed vector z_nn=np.array(initials_zz) ss=np.sum(s_n,axis=0) zz=np.sum(z_n,axis=0) rr=np.sum(r_n,axis=0) n=ss+zz+rr nn=1/n[0] tt=np.zeros((uu,uu),int) np.fill_diagonal(tt,nn) print(tt) print(nn) u=np.diag(z_n[:,0]) t=nn*(u*s_n) print(t)
so when try find nn matrix filled zeros on diagonals should have values of fractions?
use type casting. in python have type cast explicitly. following job.
in [92]: float(1)/float(225) out[92]: 0.0044444444444444444 in [95]: float(1)/225 out[95]: 0.0044444444444444444 in [96]: 1/float(225) out[96]: 0.0044444444444444444
Comments
Post a Comment