Your question, your audience. Choose who sees your identity—and your question—with question security.
import math
y = [] # empty list used as empty dynamic aray
print y # to visualize what we have before
for x in xrange(100):
y.append(math.sin(x * 20))
print y # what is inside after
print '-' * 70
# The alternative approach to simulate better the array. The list
# of 100 elements is created first. Then the "normal" indexing
# can be used to access and modify the elements.
y = [0] * 100
print y # to visualize what we have before
for x in xrange(100):
y[x] = math.sin(x * 20)
print y # what is inside after
import math
import matplotlib.pyplot as plt
y = [0] * 100
for x in xrange(100):
y[x] = math.sin(x * 20)
plt.plot(y)
plt.ylabel('sin(x)')
plt.show()
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.