All problems
Markov Chain Two Step Distribution
Problem
The distribution after two steps is p P^2, where P is the transition matrix and p the current distribution.
Given the distribution and the transition matrix as nested rows, return the distribution after two steps.
Hint
Apply the one-step update twice.
Test cases
case 1
in: [[1,0],[[0.9,0.1],[0.2,0.8]]]
expected: [0.8300000000000001,0.17000000000000004]
case 2
in: [[0.5,0.5],[[0.5,0.5],[0.5,0.5]]]
expected: [0.5,0.5]
case 3
in: [[0,1],[[0.3,0.7],[0.6,0.4]]]
expected: [0.42,0.5800000000000001]
Starter codePython
def markov_chain_two_step_distribution(p, transition):
# Your code here
pass3 test cases · run your code against them in the editor