首页 > 解决方案 > 显然缺少 scipy 功能

问题描述

当我运行下面的脚本(取自 scipy 文档)时,我收到错误 'Attribute Error: module 'scipy.integrate' has no attribute 'cumulative_trapezoid' 当我运行 dir (integrate) 时,列表中没有提及函数“累积梯形”

from scipy import integrate
import matplotlib.pyplot as plt
x = np.linspace(-2, 2, num=20)
y = x
y_int = integrate.cumulative_trapezoid(y, x, initial=0)
plt.plot(x, y_int, 'ro', x, y[0] + 0.5 * x**2, 'b-')
plt.show()

标签: scipyintegration

解决方案


cumulative_trapezoid was added to SciPy in version 1.6. You can check which version you have with import scipy; print(scipy.__version__). In older versions of SciPy, the function is called cumtrapz.


推荐阅读