我正在尝试将我的算法转换为 python 代码。算法如下:
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
我试图一步一步地转换上面的代码块。对于del1,我尝试编写python代码如下:
del1 = [[C[i-1,j]-C[i-1,j-1] for j in range(1,(m-1))]for i in range [0,int(n)]]
我收到错误 TypeError: 'type' object is not subscriptable。谁能给我关于如何将上述算法转换为python代码的起点?
编辑:
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)]
谢谢。
贾巴巴