Hello, I am a very beginner in Python. I am reading the Lecture on quant Econ website, on the part “Finite Markov chain”, there are some code I am still confusing.
- why we need to set P=np.asarray, when P is already a matrix (stochastic matrix).
And why is must be “asarray”, not array?
And I don’t understand the purpose of it “to allocate memory”, i don’t understand we need to allocate memory for what?
The questions might be silly, but I am just started and everything seem fancy to me. I tried to google but could not find appropriate answer.
Really appreciate any help!
Thanks
def mc_sample_path(P, init=0, sample_size=1000):
=== make sure P is a NumPy array ===
P = np.asarray§
=== allocate memory ===
X = np.empty(sample_size, dtype=int)
X[0] = init
=== convert each row of P into a distribution ===
In particular, P_dist[i] = the distribution corresponding to P[i,:]
n = len§
P_dist = [qe.DiscreteRV(P[i,:]) for i in range(n)]