What can I add to my function below for my isotope['State_2_complete'] up to isotope['State_640_complete'] to have values of:
isotope['State_2_complete'] - isotope['State_1_complete'],
isotope['State_3_complete'] - isotope['State_1_complete'], isotope['State_4_complete'] - isotope['State_1_complete'],
... isotope['State_640_complete'] - isotope['State_1_complete'] ?
I thought it would be as simple as:
isotope['State_{0}_complete'.format(i)] = isotope['State_{0}_complete'.format(i)] - isotope['State_1_complete']
or something like:
isotope['State_{0}_complete'.format(i)] -= isotope['State_1_complete']
But both options were only subtracting isotope['State_1_complete'] - isotope['State_1_complete'] where I get 0 values for my isotope['State_1_complete'] (which I want) but the rest of the states (e.g. isotope['State_2_complete'], isotope['State_3_complete'], ... isotope['State_640_complete']) stayed as their original values.
def create_relative_excitation_energies_66_x_640_matrix(isotope, data_tbd, data_occ):
"""
creates a 66 x 640 matrix by subtracting off the
ground state data from the excited states
"""
# counter
a = 10
b = 12
# getting our 640 states in numpy array form
for i in range (1,641):
isotope['State_{0}_inc'.format(i)] = np.genfromtxt(data_tbd, names=('a', 'b', 'c', 'd', 'J', 'T', 'X_JT(ab,cd)'),
skip_header=a, max_rows=63, usecols=6)
isotope['State_{0}_inc'.format(i)] = np.expand_dims(isotope['State_{0}_inc'.format(i)], axis=1)
isotope['State_{0}_inc'.format(i)] = isotope['State_{0}_inc'.format(i)].astype('float64')
isotope['State_{0}_spe'.format(i)] = np.genfromtxt(data_occ, names=('Particle', 'occ', 'Orbit_1', 'Orbit_2', 'Orbit_3'),
skip_header=b, max_rows=2, usecols=(2,3,4))
isotope['State_{0}_spe_sum'.format(i)] = np.vstack((isotope['State_{0}_spe'.format(i)]['Orbit_1'].sum(),
isotope['State_{0}_spe'.format(i)]['Orbit_2'].sum(), isotope['State_{0}_spe'.format(i)]
['Orbit_3'].sum()))
isotope['State_{0}_complete'.format(i)] = np.vstack((isotope['State_{0}_inc'.format(i)], isotope['State_{0}_spe_sum'.format(i)]))
####### isotope['State_{0}_complete'.format(i)] = *add code here* ###########
a = 66
b = 3
matrix = np.hstack(([isotope[f'State_{i 1}_complete'] for i in range(640)]))
return matrix
CodePudding user response:
Currently, you're doing this:
isotope['State_{0}_complete'.format(i)] = np.vstack((isotope['State_{0}_inc'.format(i)], isotope['State_{0}_spe_sum'.format(i)]))
But you say you want to update these values by subtracting the first such value off of itself and all the other ones. So, you could replace the above with:
if first is None:
first = np.vstack((isotope['State_{0}_inc'.format(i)], isotope['State_{0}_spe_sum'.format(i)]))
isotope['State_{0}_complete'.format(i)] = np.vstack((isotope['State_{0}_inc'.format(i)], isotope['State_{0}_spe_sum'.format(i)])) - first
And define first = None outside and before the loop. Since first will only be None on the first pass through, that's when it gets its value and for every assignment of those values, it will then be subtracted from them.
