x = Symbol('x')
f = x**2-3
def return_y_intercept(f):
return [the y-intercepts]
如何使用类似上面结构的东西写一个函数来返回它的参数的y-截距?
答案 0 :(得分:2)
尝试使用sympy.coeff
,here,如下所示:
Y-intercept as Coordinates
from sympy import Symbol
x = Symbol('x')
f = x**2-3
def return_y_intercept(f):
return [0,f.coeff(x,0)] #return coordintes of y-intercept
print return_y_intercept(f)
输出:
0,-3
Y截距:
from sympy import Symbol
x = Symbol('x')
f = x**2-3
def return_y_intercept(f):
return [f.coeff(x,0)] #return just the y-intercept
print return_y_intercept(f)
输出:
-3
在在线口语翻译here
上试试答案 1 :(得分:2)
y-intercept只表示你用0代替x,所以只做f.subs(x, 0)
。