在 Spyder 中针对每个使用的 Scipy 函数引发 DeprecationWarning

DeprecationWarning rasied in Spyder for every Scipy function used

我在 Spyder 中编码并且代码运行,但是 使用 sp.___ 的行都会引发 DeprecationWarning,例如DeprecationWarning: scipy.array is deprecated and will be removed in SciPy 2.0.0, use numpy.array instead.

为什么 Spyder 会这样做?我该如何使用 scipy 而不会引发此错误?如果做不到这一点,我可以做些什么来抑制每次弹出错误?

代码是这样的:

import matplotlib.pyplot as plt,scipy as sp
import scipy.optimize as op
a=9.3779
x_in=sp.array([.095,.065,.09,.108,.125,.115,.040,.055,.055])
x=(x_in+14)
y_in=sp.array([.2,.6,.5,.4,.1,.3,-0.2,-0.4,0])
y=y_in+45
ax.plot(x_in,y_in,'ro')
plt.show()

这引发了错误:

C:\Users\Shiva Pingle\Desktop\python\others\peaks.py:38: DeprecationWarning: scipy.array is deprecated and will be removed in SciPy 2.0.0, use numpy.array instead x_in=sp.array([.095,.065,.09,.108,.125,.115,.040,.055,.055]) C:\Users\Shiva Pingle\Desktop\python\others\peaks.py:40: DeprecationWarning: scipy.array is deprecated and will be removed in SciPy 2.0.0, use numpy.array instead y_in=sp.array([.2,.6,.5,.4,.1,.3,-0.2,-0.4,0])

您在评论中的解决方案将使您忽略所有弃用警告。不建议这样做。

您可以改为 import numpy as np 并使用 np.array()

更正后的代码:

import matplotlib.pyplot as plt,scipy as sp
import scipy.optimize as op
import numpy as np    # Added import of numpy

a=9.3779

x_in=np.array([.095,.065,.09,.108,.125,.115,.040,.055,.055]) # Changed sp to np
x=(x_in+14)

y_in=np.array([.2,.6,.5,.4,.1,.3,-0.2,-0.4,0]) # Changed sp to np
y=y_in+45

plt.plot(x_in,y_in,'ro') # Also changed the ax to plt
plt.show()