2014-07-24 14:53 GMT+02:00 fl <rxjw...@gmail.com>: > Hi, > I have read a lot about Python, but it still has a problem now on a simple > exercise. For example, I want to generate a sine curve. First, I get a time > sequence: > > index=range(100) > > I import math module, try to calculate sine with > > math.sin(index*math.pi/2) > > but it fails. > > It is possible to use a for loop, but I don't know how to save each result to > an > array. > > I have gone through several tutorial, but they are all about using print right > away. I want to get an array, or a series, then plot it with > > import matplotlib.pyplot as plt > > I have installed plot module and it works already. I am a little hurry for an > project interview and would like to ask here besides I continue search on > tutorial. > > > Thanks, > --
Hi, depending on your actual needs, you may also try a specialised library like mpmath, which also supports plotting (and uses matplotlib internally): http://mpmath.org/ Using the sensible defaults, the plotting of a function can be as simple as: mpmath.plot(mpmath.sin) As for your original question, you can use a library designed for working with this data: http://www.numpy.org/ numpy.arange(100) * numpy.pi hth, vbr -- https://mail.python.org/mailman/listinfo/python-list