Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.026 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'python,': 0.02; 'already.': 0.09; 'data:': 0.09; 'matplotlib': 0.09; 'subject:method': 0.09; 'array.': 0.16; 'curve.': 0.16; 'defaults,': 0.16; 'fails.': 0.16; 'sequence:': 0.16; 'thanks,': 0.17; 'library': 0.18; 'module': 0.19; 'import': 0.22; 'print': 0.22; 'module,': 0.24; 'math': 0.24; 'first,': 0.26; 'header:In- Reply-To:1': 0.27; 'installed': 0.27; 'function': 0.29; 'besides': 0.30; 'message-id:@mail.gmail.com': 0.30; 'away.': 0.31; 'actual': 0.34; 'subject:the': 0.34; 'problem': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'possible': 0.36; 'subject:?': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'example,': 0.37; 'project': 0.37; 'question,': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'read': 0.60; 'gone': 0.61; 'interview': 0.61; 'simple': 0.61; 'save': 0.62; 'skip:n 10': 0.64; 'needs,': 0.65; 'here': 0.66; 'as:': 0.81; 'subject:get': 0.81; 'exercise.': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=RzN29BMI3pRu5KCdmmfFJ2Q8cmxUfhD5D3Ohiz0Z9RU=; b=VVc3uTyKJrVyL5ecdiLJ7jj3skKIyFGIaMH/Zmz78SaeAt6wzigAvmOZCbsL1yDGBG G5Isda7zTAoMe5q7gn2CJziiry+nB4XmbWOhUKnhWipqaI0+K5wTO/FXly/hEubUkWe4 QSpxa4PvIdZmt7Uj765FJeZIppvgN3FoHHpjIkDBuSj0lZhg6s3YohY/hymgh1+835NS foF+6iFIvRJCFyyZYOoQfTYwX8lI1QpKjpItZT9DOgqdxIDvoAlGKwR/evbF7JcaCldO FiwREZqM2et/je6qyLOLVcksFo9GrBx9a7XcLgmLdnIYZMwlz4fQp5tkLOET1NuTGDSU py4w== MIME-Version: 1.0 X-Received: by 10.60.146.198 with SMTP id te6mr13374764oeb.46.1406209754075; Thu, 24 Jul 2014 06:49:14 -0700 (PDT) In-Reply-To: <95524a09-7792-4cec-8c7e-7525a358ee8c@googlegroups.com> References: <95524a09-7792-4cec-8c7e-7525a358ee8c@googlegroups.com> Date: Thu, 24 Jul 2014 15:49:14 +0200 Subject: Re: What is the simplest method to get a vector result? From: Vlastimil Brom To: python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1406209762 news.xs4all.nl 2973 [2001:888:2000:d::a6]:59863 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75142 2014-07-24 14:53 GMT+02:00 fl : > 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