Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97308 > unrolled thread
| Started by | Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt> |
|---|---|
| First post | 2015-10-01 21:45 +0100 |
| Last post | 2015-10-02 02:01 +0100 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.python
Generating a vector from successive multiplications of another vector from an initial value Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt> - 2015-10-01 21:45 +0100
Re: Generating a vector from successive multiplications of another vector from an initial value Ian Kelly <ian.g.kelly@gmail.com> - 2015-10-01 15:10 -0600
Re: Generating a vector from successive multiplications of another vector from an initial value duncan smith <buzzard@invalid.invalid> - 2015-10-02 00:44 +0100
Re: Generating a vector from successive multiplications of another vector from an initial value Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt> - 2015-10-02 02:01 +0100
| From | Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt> |
|---|---|
| Date | 2015-10-01 21:45 +0100 |
| Subject | Generating a vector from successive multiplications of another vector from an initial value |
| Message-ID | <muk61h$eka$1@speranza.aioe.org> |
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. Thanks
[toc] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2015-10-01 15:10 -0600 |
| Message-ID | <mailman.310.1443733899.28679.python-list@python.org> |
| In reply to | #97308 |
On Thu, Oct 1, 2015 at 2:45 PM, Paulo da Silva
<p_s_d_a_s_i_l_v_a_ns@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)
[toc] | [prev] | [next] | [standalone]
| From | duncan smith <buzzard@invalid.invalid> |
|---|---|
| Date | 2015-10-02 00:44 +0100 |
| Message-ID | <560dc554$0$3212$862e30e2@ngroups.net> |
| In reply to | #97308 |
On 01/10/15 21:45, 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. > > Thanks > Maybe, http://docs.scipy.org/doc/numpy/reference/generated/numpy.cumprod.html Duncan
[toc] | [prev] | [next] | [standalone]
| From | Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt> |
|---|---|
| Date | 2015-10-02 02:01 +0100 |
| Message-ID | <mukl25$cos$1@speranza.aioe.org> |
| In reply to | #97308 |
Às 23:36 de 01-10-2015, Oscar Benjamin escreveu: > > On Thu, 1 Oct 2015 21:51 Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt > <mailto:p_s_d_a_s_i_l_v_a_ns@netcabo.pt>> wrote: ... > > V * np.cumprod(vec) > Thank you very much Oscar and Duncan. I googled a lot for such a function. Unfortunately the word "cumulative" didn't come to my mind! Paulo
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web