Reputation: 11
Learning data visualisation with python and numpy, provided with an example in a Jupyter notebook
What does y=np.zeros(len(x))
do in this definition? Set y = 0?
x=np.linspace(-2*np.pi,2*np.pi,100)
# i-th order sine series decomposition
from math import factorial
def sineseries(x,order):
y=np.zeros(len(x))
for i in range(order):
y=y+(-1.)**i/factorial(2*i+1)*x**(2*i+1)
return y
for i in range(20):
plt.figure()
plt.plot(x,sineseries(x,i),'.')
plt.plot(x,np.sin(x),'k')
Upvotes: 1
Views: 2944
Reputation: 7430
It creates an array with len(x)
zeros.
For example if x has 3 elements then the resulting array will be [0, 0, 0]
Upvotes: 1