python - Python 可见的弃用警告

标签 python numpy integer

我正在尝试用 python 为经济学论文建立一个模型并计算函数:

elif wage_online == max(wages):
            # after going to online you get the highest wage after cost of education
            learning_benefit = int(np.int((1 + gamma_online_learning) * x[0]) * exp(np.int(bivariate_distribution[x[0] - 1, x[1] - 1])))
            social_benefit = int(((1 + gamma_online_social) * np.int(x[1])) * exp(np.int(bivariate_distribution[x[0] - 1, x[1] - 1])))
            sigma_social.append(social_benefit)
            sigma_learning.append(learning_benefit)

我收到以下错误

/Users/sa/Documents/Dissertation/first_defiation.py:160: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  learning_benefit = int(np.int((1 + gamma_online_learning) * x[0]) * exp(np.int(bivariate_distribution[x[0] - 1, x[1] - 1])))

我尝试通过将 exp 函数中的值包含为 np.int 来解决此问题,但无济于事。有谁知道警告来自哪个变量?

最佳答案

看起来您错过了方括号内需要 int 的地方:

social_benefit = (1 + gamma_online_social) * x[1] * exp(
    bivariate_distribution[int(x[0] - 1), int(x[1] - 1)]   # needed here for indexing
)

将来,您可以使用 warnings.filterwarnings('error') 来查找警告的准确回溯,这将指向您 __getitem__

关于python - Python 可见的弃用警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42866662/

相关文章:

c++ - 不能使用 push_back 将整数插入 1D/2D vector

java - 对对象数组列表中的整数进行排序

python - 如何在不更新 tensorflow 模型的情况下计算损失

切换对象的 Pythonic 方式 "behind the scenes"

python - 使用HTTPS的网站,通过POST上传的文件是否加密?

python - 对列表进行重复采样

python - 关于python离散卷积的问题

python - NumPy 错误 : 'numpy.ndarray' object is not callable

Java:如何打印整数对象的引用?

python - 如何将 Bokeh 图标更改为其他图像