0

I want to make numpy.piecewise function based on lambdas defined with parameters in lists. To illustrate the problem in the title, here's a simpler example:

import numpy as np
import matplotlib.pyplot as plt

xx = np.linspace(0,5,101)
powers = [1,2]
funcs = []

for i in range(2):
    power = powers[i]
    funcs.append(lambda x: x**power)
    
f1, f2 = funcs

plt.plot(xx,f1(xx))

f1 should be the linear function and f2 should be the quadratic function, but they're both quadratic. I'm not sure why.

John Kugelman
  • 330,190
  • 66
  • 504
  • 555
Aaron
  • 1

0 Answers0