What is the simplest method to get a vector result?

Vlastimil Brom vlastimil.brom at gmail.com
Thu Jul 24 15:49:14 CEST 2014

2014-07-24 14:53 GMT+02:00 fl <rxjwg98 at 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,
> --

depending on your actual needs, you may also try a specialised library
like mpmath, which also supports plotting (and uses matplotlib
Using the sensible defaults, the plotting of a function can be as simple as:


As for your original question, you can use a library designed for
working with this data:

numpy.arange(100) * numpy.pi


More information about the Python-list mailing list