Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Numpy – How to get an array of the pattern gamma^t for some 0-t?

I am creating a basic gridworld RL problem and I need to calculate the return for some given episode. I currently have the array of rewards, and I would like to element-wise multiply this with a list of the form:

[gamma**0, gamma**1, gamma**2, ....]

In order to get:

[r_0*gamma**0, r_1*gamma**1, r_2*gamma**2, ....]

and then use np.sum() to get the entire return.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I complete that first step? I tried using Logspace, but it isn’t quite what I want (or I’m doing it wrong).

>Solution :

if the example if like this for reward array and gamma is some value:

n = 20    
reward = np.random.randint(0, 10, n)
gamma = 2

np.sum(reward * (gamma ** np.arange(n)))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading