python - SymPy Comparison and Conditional -
what sympy equivalent of mathematica function: f[x_]:=if[x==infinity,1,2]
?
if tried without success:
lambdify(x,piecewise((1, <expr> ),(2,true))
where <expr>
1 of
1)
eq(x,oo)
2)
simplify(x)==oo
3)
eq(x+1,x)
the correct expression should piecewise((1, eq(x, 0)), (2, true))
. ==
structural comparison , not create symbolic object (see http://docs.sympy.org/latest/tutorial/gotchas.html#equals-signs).
this works me
in [3]: f = lambdify(x, piecewise((1, eq(x, 0)), (2, true))) in [4]: f(0) out[4]: 1 in [5]: f(1) out[5]: 2
Comments
Post a Comment