1

In the code I have gotten from my previous issue: issue I could use iterations whilst modifying the a value of multiplication. I want to use the .prod function but with iterations of multiplication, division and addition. The calculations will go as follows, for the first calculation 10 + 10 *50/100 = 15 with the equation (Starting_val + Starting_val * Random_numb/100). The first element in Random_numb is 50 and Starting_val is updated to the value of 15. So for the second calculations it will be 15 + 15 *74/100 = 26.1 The value of the Starting_val is updated from 15 to 26.1 in the second calculation. I do not how to iterate this function with numpy. I wish to not use a for loop for this function.

import numpy as np

Starting_val = 10
Random_numb = np.array([50, 74, 5, 69, 50])

Random_numb.prod(initial=Starting_val)
Starting_val + Starting_val * Random_numb/100

Expected Output:

[15, 26.1, 27.405, 46.314, 69.471 ]
2
  • What is your expected output? [15, 26.1, ...] or only the last updated value for starting value? Commented Feb 7, 2021 at 19:14
  • 1
    I will update the issue and print an expected output Commented Feb 7, 2021 at 19:15

1 Answer 1

2

Simple artithmetic transformations give you

Starting_val * np.cumprod(Random_numb / 100 + 1)

Result:

array([15.      , 26.1     , 27.405   , 46.31445 , 69.471675])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.