Path: csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.077 X-Spam-Evidence: '*H*': 0.85; '*S*': 0.00; 'subject:skip:m 10': 0.09; 'subject: \n ': 0.15; 'thu,': 0.15; 'numpy': 0.16; 'paulo': 0.16; 'wrote:': 0.16; '2015': 0.20; 'header:In-Reply-To:1': 0.24; 'all.': 0.24; 'message-id:@mail.gmail.com': 0.27; 'fastest': 0.27; 'initial': 0.28; 'looks': 0.29; 'received:google.com': 0.35; 'something': 0.35; 'depends': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'skip:v 20': 0.38; 'subject:from': 0.39; 'to:addr:python.org': 0.40; 'better.': 0.66; '2:45': 0.84; 'subject:value': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=zLH2pOWgS0GsYTHqO504ua5PwXWglfoDtH4ySQ3cxec=; b=vx9jxB2Rlw4DFUgznacg9+cqlPsoU+V8eg2bKM/p8ot1/Te8iOcarEJQybEMVW9pju gmq5QDUNzikbRxKpjLkUKVbZ7Jm4Sh9M7ljuMh6hdk1Id5druDGi9M/HxntOiKF+w2Of Gxc23OJNP438L+v2y0oeK2p72HuThhgfzOgIWxM3++5ZB4dg9ee+QPObJgF8ANLrHwDD Y08lnlqA6cpXvrSst+6d+6MAq7TGUSpS21uHmstT9Px/Fea1d+voxnGyf0W/b3FqI+MJ gXBMQjiaJH0U+fe2U8itRLr/YgBgZDkLQ2B1hrPueR5IU51tO6H2hRsfHH49E8SbECPR VyUw== X-Received: by 10.13.204.81 with SMTP id o78mr10469498ywd.108.1443733890348; Thu, 01 Oct 2015 14:11:30 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Thu, 1 Oct 2015 15:10:50 -0600 Subject: Re: Generating a vector from successive multiplications of another vector from an initial value To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1443733899 news.xs4all.nl 23777 [2001:888:2000:d::a6]:49002 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:97309 On Thu, Oct 1, 2015 at 2:45 PM, Paulo da Silva wrote: > Hi all. > > What is the fastest way to do the following: > > I have an initial value V and a vector vec of (financial) indexes. > I want to generate a new vector nvec as > > V, V*vec[0], V*vec[0]*vec[1], V*vec[0]*vec[1]*vec[2], ... > > A numpy vectorized solution would be better. That looks hard to vectorize since each calculation depends on the previous. You might be stuck with something like: result = [V] for x in vec: result.append(result[-1] * x)