Using multiple arrays, multiple for statements, first and second, respectively. To get the last value

Asked 2 years ago, Updated 2 years ago, 56 views


    import numpy as np

    T_list = []
    Temp_k = np.linspace(298, 398, 10)
    #print (Temp_k)
    current = np.linspace(0, 1.4, 5)
    ppH2O = np.linspace(-2, -1, 5)

    H2_pressure = []
    H2O_pp = ppH2O
    for i in (Temp_k):
        print(i, 'i')
        for j in (H2O_pp):
            print(j, 'j')
            for k in (current):
                print (k, 'k')
                partial_H2 = 5*np.exp((1.653 * k)/i) - 1/j
    H2_pres1sure.append(partial_H2)
    #print (H2_pressure)

Temp_k, H2O_pp, and current are defined as i, j,k, respectively.

partial_H2 = 5*np.exp((1.653 * k)/i) - 1/j

When this is the first value of Temp_k, H2O_pp, current, second, third... I'd like to get the last value as array or list, so what's the method?

For the current output, i = the first value j = the first value k = the first to the last value i = the first value j = the second value k = the first to last value

It comes out like this.

The way I want to get it is i = first j = first k = first i = second j = second k = second k ................................................ i = last j = last k = last

I'd like to get it this way.

python for

2022-09-20 17:08

1 Answers

import numpy as np

T_list = []
Temp_k = np.linspace(298, 398, 10)
#print (Temp_k)
current = np.linspace(0, 1.4, 5)
ppH2O = np.linspace(-2, -1, 5)

H2_pressure = []
H2O_pp = ppH2O

for i in (Temp_k):
    #print(i, 'i')    
    for j in (H2O_pp):
        #print(j, 'j')    
        for k in (current):        
            #print (k, 'k')            
            partial_H2 = 5*np.exp((1.653 * k)/i) - 1/j
            H2_pressure.append(partial_H2)

print(H2_pressure)            

Is this what you want?


2022-09-20 17:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.