Search code examples
functionintegerargumentspiecewise

piecewise numpy function with integer arguments


I define the piecewise function

def Li(x):        
    return piecewise(x, [x < 0, x >= 0], [lambda t: sin(t), lambda t: cos(t)])

And when I evaluate Li(1.0)

The answer is correct

Li(1.0)=array(0.5403023058681398),

But if I write Li(1) the answer is array(0).

I don't understand this behaviour.


Solution

  • This function runs correctly.

    def Li(x):        
      return  piecewise(float(x), 
                        [x < 0, x >= 0], 
                        [lambda t: sin(t), lambda t: cos(t)])