0

Hi there trying to just get values for simple fractions like 1/225 or 35/75 but it keeps returning zeros? Any help would be 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 you try to find NN you get a matrix filled by zeros on the diagonals but it should have the values of the fractions?

Eric
  • 95,302
  • 53
  • 242
  • 374

1 Answers1

-1

Use type casting. As in python you have to type cast explicitly. The following will do your 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
hrishi
  • 443
  • 2
  • 12