Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75142

Re: What is the simplest method to get a vector result?

References <95524a09-7792-4cec-8c7e-7525a358ee8c@googlegroups.com>
Date 2014-07-24 15:49 +0200
Subject Re: What is the simplest method to get a vector result?
From Vlastimil Brom <vlastimil.brom@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.12275.1406209762.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

What is the simplest method to get a vector result? fl <rxjwg98@gmail.com> - 2014-07-24 05:53 -0700
  Re: What is the simplest method to get a vector result? Alan <alan.isaac@gmail.com> - 2014-07-24 06:10 -0700
  Re: What is the simplest method to get a vector result? Vlastimil Brom <vlastimil.brom@gmail.com> - 2014-07-24 15:49 +0200
    Re: What is the simplest method to get a vector result? fl <rxjwg98@gmail.com> - 2014-07-25 16:08 -0700
      Re: What is the simplest method to get a vector result? Ian Kelly <ian.g.kelly@gmail.com> - 2014-07-25 18:37 -0600
        Re: What is the simplest method to get a vector result? fl <rxjwg98@gmail.com> - 2014-07-25 19:17 -0700
  Re: What is the simplest method to get a vector result? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-24 14:06 +0000
  Re: What is the simplest method to get a vector result? Marko Rauhamaa <marko@pacujo.net> - 2014-07-24 17:25 +0300
    Re: What is the simplest method to get a vector result? fl <rxjwg98@gmail.com> - 2014-07-24 18:29 -0700
      Re: What is the simplest method to get a vector result? Ian Kelly <ian.g.kelly@gmail.com> - 2014-07-24 19:50 -0600
      Re: What is the simplest method to get a vector result? Dave Angel <davea@davea.name> - 2014-07-24 22:44 -0400
        Re: What is the simplest method to get a vector result? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-25 03:23 +0000

csiph-web