如何在诽谤中使用类方法?
我目前正在尝试弄清楚如何在导入的诽谤中使用方法。例如,我们可以使用 scipy.inerpaly.interp2d 函数: https:> https://docs.scipy.org/doc/ scipy/reference/gostated/scipy.interpaly.interp2d.html
from scipy import interpolate
x = np.arange(-5.01, 5.01, 0.25)
y = np.arange(-5.01, 5.01, 0.25)
xx, yy = np.meshgrid(x, y)
z = np.sin(xx**2+yy**2)
f = interpolate.interp2d(x, y, z, kind='cubic')
import matplotlib.pyplot as plt
xnew = np.arange(-5.01, 5.01, 1e-2)
ynew = np.arange(-5.01, 5.01, 1e-2)
znew = f(xnew, ynew)
plt.plot(x, z[0, :], 'ro-', xnew, znew[0, :], 'b-')
plt.show()
在页面底部列出了此功能的所有方法。现在我想知道,如何使用此方法?
scipy.interpaly.inerp2d(x,y,z,kind =“ cutic”)。__调用__
不起作用。
此外,我想了解为什么在某人只能使用函数输入时需要将方法添加到函数之间的区别?
I am currently trying to figure out how to use methods in imported libaries. For example we can take the scipy.inerpolate.interp2d function:
https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp2d.html
from scipy import interpolate
x = np.arange(-5.01, 5.01, 0.25)
y = np.arange(-5.01, 5.01, 0.25)
xx, yy = np.meshgrid(x, y)
z = np.sin(xx**2+yy**2)
f = interpolate.interp2d(x, y, z, kind='cubic')
import matplotlib.pyplot as plt
xnew = np.arange(-5.01, 5.01, 1e-2)
ynew = np.arange(-5.01, 5.01, 1e-2)
znew = f(xnew, ynew)
plt.plot(x, z[0, :], 'ro-', xnew, znew[0, :], 'b-')
plt.show()
At the bottom of the page there are listed all methods of this function. Now I am wondering, how do I use this method?
scipy.interpolate.inerp2d(x, y, z, kind="cubic").__call__
didn't work.
Furthermore I would like to understand the difference between why there is a need to add methods to functions when someone could just use the function input?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
__调用__()
方法是所谓的Dunder方法或一种特殊方法。这就是使您能够做f()
之类的事情。由于Python中的所有内容都是一个对象,因此ACollable
只是支持调用语法f()
的对象或实例。在这种情况下,scipy
函数您要导入并使用返回函数。您粘贴的示例使您正确使用该功能。
The
__call__()
method is what's known as a dunder method, or a special method. It is what enables you to do things likef()
. Since everything in python is an object, acallable
is simply an object or instance that supports the call syntaxf()
. In this case, thescipy
function you are importing and using returns a function.The example you pasted has you using the function properly.