Я установил такую функцию:
def triangular(x, a, b, c):
if x <= a:
return 0
if a < x <= b:
return (x - a)/(b - a)
if b < x <= c:
return (c - x)/(c - b)
if c < x:
return 0
Я хочу нарисовать изображение этой функции, поэтому я использую:
x = range(-10, 10, 0.1)
y = triangular(x,1,2,3)
plt.figure()
plt.plot(x,y)
plt.show()
Тем не менее, он показывает ошибку: 'float' object cannot be interpreted as an integer
, Почему? мне нужно исправить свою функцию или ввод?
Я пытался изменить на
x = np.arange(-10, 10, 0.1)
y = triangular(x,1,2,3)
plt.figure()
plt.plot(x,y)
plt.show()
, это показывает
The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()