I am trying to convert my algorithm into python code. The algorithm is as follows:
For i = 1 To n
For j = 1 To (m - 1)
del1 = C(i - 1, j) - C(i - 1, j - 1)
del2 = C(i - 1, j + 1) - C(i - 1, j)
If del2 = 0 Then
r = 0
Else
r = del1 / del2
End If
Next i
I tried to convert the above chunk of code step by stop. For del1 I tried to write the python code as follows:
del1 = [[C[i-1,j]-C[i-1,j-1] for j in range(1,(m-1))]for i in range [0,int(n)]]
I get the error TypeError: ‘type’ object is not subscriptable. Can anyone give me starting point on how to convert the above algorithm into python code ?
Edit:
C = [[0 for j in range(0,int(m))]for i in range(0)]
C = [[1 for i in range(0,int(n))]for j in range(0)]
Thanks.
Jdbaba
should be:
[]->()on the lastrangeThe above notation will work if
Cis something like anumpyarray that supports multi-dimensional slicing. IfCis a list of lists, the following should work: