Hi,
I'm trying to write a symbolic numpy.clip function[1], to be used in
expressions (it's ok if it doesn't get simplified) and in lambdify
(and consequently evaluated by numpy). Doing this in pure numpy would
be trivial, but it doesn't work well with my current code (and would
be inelegant).
I've tried something like this, in the hope that the function will
remain unevaluated except when an numpy array is passed to it, but
it's not working: (inspired by [2])
class MyClip(sympy.Function):
@classmethod
def eval(cls, arg1, arg2, arg3):
if isinstance(arg1, np.ndarray):
return np.clip(arg1, arg2, arg3)
Am I missing something obvious here, or not specifying "eval" in the
correct way? Perhaps my whole approach is wrong, but I cannot see a
better solution.
Thanks for any help!
[1] Clip limits the values in an array: given an interval, values
outside the interval are clipped to the interval edges: np.clip(a,
a_min, a_max)
[2] How to define a symbolic function:
https://groups.google.com/forum/#!topic/sympy/sk4K-VWBRRQ