python code for Video 2 lectures


(Kiran) #1

Here is the python code for the questions in the Video 2

Matrix-Vector Products:
The matrix below gives the probabilities of moving from 1 health state to another in 1 year. If the current health states for a group are:

85% asymptomatic
10% symptomatic
5% AIDS
0% death
what will be the % in each health state in 1 year?
import numpy as np
stochasticMtx = np.array ([[0.9, 0.07, 0.02, 0.01],
[0, 0.93, 0.05, 0.02],
[0, 0, 0.85, 0.15],
[0, 0, 0, 1]])

print (stochasticMtx)
initial_state = np.array ([0.85, 0.1, 0.05, 0]).reshape (1, 4)
print (stochasticMtx.shape)
print (initial_state.shape)
state_after_1_year = initial_state.dot (stochasticMtx)
print (state_after_1_year)