Kevin
Kevin

Reputation: 65

Filling out a matrix in python using a for loop

I'm trying to convert some MATLAB code to python but I'm stuck on this for loop to fill out a matrix. Here is the MATLAB

for t=0:(Num-1)
  for j= 1:2
      ExpD(j,j) = exp(V(j,j)*t*Step)
  end
  Output(:,t+1) = V*expD
end

And here is my attempt at the python

    for t in range(0,Num-1):
        for j in range(1,2):
            ExpD[j,j]=ma.exp(D[j,j[*t*Step)
        Output[:,t+1] = V*expD

I'm getting an error saying there are too many indices for the array though. Thanks for the help.

Upvotes: 0

Views: 64

Answers (1)

KM_83
KM_83

Reputation: 727

check for j in range(1,2) is correct. You might want range(1,3).

Upvotes: 1

Related Questions