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
Title | # Comments | Views | Activity |
---|---|---|---|
Updating urls.py doesn't work | 4 | 85 | |
How best should I print a graphical chess game state with Python? | 6 | 87 | |
need cgi page to refresh one time only after launch | 11 | 143 | |
How does this Python sort work? | 5 | 88 |
Join the community of 500,000 technology professionals and ask your questions.