
editĬorrectly expanding the two sided tests: In : expr = np.piecewise((0, x-a <= -2*h), The numpy expression has multiple True/False values, and can't be used im a Python expression that requires a simple True/False. ValueError: The truth value of an array with more than one element is ambiguous. The error is telling us that a sympy.Relational does not work. Python if is simple True/False switch its argument must evaluate to one or the other. > 1 if x 384 raise TypeError("cannot determine truth value of Relational") This expression is a sympy relational: In : x in > 384 raise TypeError("cannot determine truth value of Relational")

usr/local/lib/python3.8/dist-packages/sympy/core/relational.py in _nonzero_(self) > 1 0 384 raise TypeError("cannot determine truth value of Relational") > 1 -2*h 384 raise TypeError("cannot determine truth value of Relational") Let's try something smaller: In : expr = np.piecewise((0, x-a in ġ expr = np.piecewise((0, x-a 2 ((1/6)*(2*h+(x-a))**3, -2*h 384 raise TypeError("cannot determine truth value of Relational")Īnd smaller pieces: In : (0, x-a in Somethings work, many others don't.ĭid you try a small expression? Good programming practice is to start with small pieces, making sure those work first. While np.piecewise is a numpy function, because x is a sympy.Symbol, the equations are sympy expressions. > 1 expr = np.piecewise((0, x-a 384 raise TypeError("cannot determine truth value of Relational")
Piecewise functions code#
At the very least we need to identify which line of your code is producing the problem. Lets look at the whole traceback, not just one line of it. I've seen a lot of the numpy ambiguity error, but not this sympy relational error.

I had to look at the tracebacks and test small pieces of your code to identify the exact problem.
Piecewise functions full#
Sorry about the length of this answer, but I think you need to see the full debugging process. TypeError: cannot determine truth value of Relational Return (2*(h**3/3)-0.5*(x-a)**2*(2*h+(x-a))) īoth ways I get this : raise TypeError("cannot determine truth value of Relational") This is my code: from numpy import piecewiseįrom import lambdify, implemented_function I want to be able to then evaluate this function at different points as well as expressions like f(X-1) etc

I tried defining using numpy.piecewise function object and also using just elif commands as a definition. I am getting Type Errors when defining a function. Following is the function I want to implement in python.
