为什么这个除法的结果是"inf"?

Why is the result of this division "inf"?

我有以下代码来计算所需数量:

import numpy as np

N = 2
lamda = 2
mu = 1
a = 0.5
St_Sp = np.arange(- N, N + 1)
Card = St_Sp.shape[0]

#%% Define infintesimal generator
def In_Ge(x, y):
    if x == N or x == - N:
        re = 0
    elif x - y == - 1:
        re = lamda
    elif x - y == 1:
        re = mu
    elif x - y == 0:
        re = - (mu + lamda)
    else: re = 0
    return re

x = St_Sp[0]
y = In_Ge(x, x) / (In_Ge(x, x) + np.log(a))
b = - 1 / y

print(b)

结果是inf。我查了下 y 的值是非零的,所以我不明白为什么会出现这种现象。你能详细说明一下这个问题吗?

@pinegulf 的评论解决了我的问题:

Your 'In_Ge(x,x)' retruns 0, thus y= 0 and 1/0 is pretty badly defined. Edit: You say it's not, but your x==--2 and functions first if is invoked.