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

Updating value at each iteration using python

I want to get updated value of Pw at each iteration. For first iteration, it takes minimum value of first row and subtracts from Pw1. For second iteration, I want it to take this updated Pw (not Pw1) and subtract the minimum of second row.

import numpy as np
Pe=np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])
Pw1=100
Pe_min=Pe.min(axis=1)

for i in range(4):
    Pw=np.zeros(4)
    Pw[i]=Pw1-Pe_min[i]
    print(Pw)

The current output is

99
95
91
87

The output I am seeking is

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

99
94
85
72

>Solution :

Basically,
You should update the Pw1 value in the each iteration. So you can add

Pw1-=Pe_min[i]

Full Code;

import numpy as np
Pe=np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])
Pw1=100
Pe_min=Pe.min(axis=1)
for i in range(4):
    Pw=np.zeros(4)
    Pw[i]=Pw1-Pe_min[i]
    Pw1-=Pe_min[i]
    print(Pw)
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