Generating a vector from successive multiplications of another vector from an initial value

Ian Kelly ian.g.kelly at gmail.com
Thu Oct 1 17:10:50 EDT 2015


On Thu, Oct 1, 2015 at 2:45 PM, Paulo da Silva
<p_s_d_a_s_i_l_v_a_ns at netcabo.pt> 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)



More information about the Python-list mailing list