嵌入我想要做这样的事情:绘制拉姆达与如果在Python语句中使用pyplot
import numpy as np
import matplotlib.pyplot as plt
xpts = np.linspace(0, 100, 1000)
test = lambda x: 0.5 if x > 66 else 1.0
plt.plot(xpts, test(xpts))
,但我得到的错误:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
在另一方面,我能要做到:
print(test(50), test(70))
1.0 0.5
这是怎么回事有没有解决方案?