python - A variable assigned to all rows of a column, enters a loop with only the value of the last row -
edit
in code analysis.py have written, variable entropy column of data.
when pass rows loop, last value considered:
to run code, necessary 2 files in folder:
pressure_enthalpy_all_points.dat:
# pressure enthalpy 2 3 5 4 3.5 2 entropies_parsed.dat:
# entropies 0.5 0.2 0.47 code analysis.py included nested loop comments:
import numpy np pressure_gibbs = open('pressure_gibbs_all_points.dat', 'w') pressure_gibbs.write('#pressure gibbs\n') ## function: def g(h,s): # g = h - ts # then: gibbs = h - 298.15 * s/4.0 return gibbs open('entropies_parsed.dat') entropies_parsed, open('pressure_enthalpy_all_points.dat') enthalpy_pressure: # open file entropies_parsed.next() # skip first line enthalpy_pressure.next() line in entropies_parsed: # iterate on remaining lines entropy = float(line) line in enthalpy_pressure: pressure, enthalpy = [float(n) n in line.split()] gibbs = g(enthalpy, entropy) pressure_gibbs.write('{}\t{}\n'.format (pressure, gibbs)) pressure_gibbs.close() this gives file, pressure_gibbs_all_points.dat:
#pressure gibbs 2.0 -34.26875 5.0 -33.26875 3.5 -35.26875 that gibbs = -34.26875 result of making 3 -298.15 * 0.5 / 4.0 , where: 3 = pressure (1st row of pressure_enthalpy_all_points.dat file) , 0.5 = entropy (1st row entropies_parsed.dat)
obviously wrong.... gibbs rows have same value because 2nd , 3rd rows of pressure_gibbs_all_points.dat have been generated 1st row of pressure_enthalpy_all_points.dat , 1st row of entropies_parsed.dat .
i can't see problem here, nth row of gibbs should generated nth rows of pressure_gibbs_all_points.dat , pressure_enthalpy_all_points.dat
there problem in looping .first loop execute , entropy variable hold final value in file . when enter second loop , print , see final entry of entropy. guess meant write nested loop there!
Comments
Post a Comment