【发布时间】:2016-05-26 23:15:16
【问题描述】:
我的目标是绘制一个具有两个变量 t 和 x 的函数。 如果 0,我们将 0 分配给 x
import matplotlib.pyplot as plt
import numpy as np
t=np.linspace(0,5,100)
def x(i):
if i <= 1:
j = 1
else :
j = 0
return j
y = 8*x(t)-4*x(t/2)-3*x(t*8)
plt.plot(t,y)
plt.ylabel('y')
plt.xlabel('t')
plt.show()
它返回一个错误:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
【问题讨论】:
标签: python function matplotlib plot conditional