【发布时间】:2017-09-17 14:29:33
【问题描述】:
我刚刚发布了一个类似的代码,但现在有一个不同的问题。假设我将 y 绑定为 0 或 1,并且我希望我的 x 具有大量值,我如何让 x 和 y 达到相同的维度?
#Part A - Plot function against values of variable x
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate as quad
import math
#Make heaviside "theta" function
def heaviside (x):
if np.any(x >= 0):
return 1
else:
return 0
#Plot
x = np.linspace(-5,5,11)
y = heaviside(x)*[1-heaviside(x-1)]
plt.plot(x, y)
plt.show()
【问题讨论】:
标签: python-3.x function matplotlib dimensions