I’m trying to write the output data of this for loop in a .csv file. However, what gets written in the .csv file with the current code is the data of a single iteration. I want to append and write the data in a new row for each iteration. How do I do that?
JavaScript
x
23
23
1
for i in range(0,8):
2
# for j in range (0,2):
3
gyro_xy_orth = (np.dot(H[i,:], xy_orth)/np.square(xy_norm))*xy_orth
4
gyro_xy = H[i,:] - gyro_xy_orth
5
gyro_xz_orth = (np.dot(H[i,:], xz_orth)/np.square(xz_norm))*xz_orth
6
gyro_xz = H[i,:] - gyro_xz_orth
7
gyro_yz_orth = (np.dot(H[i,:], yz_orth)/np.square(yz_norm))*yz_orth
8
gyro_yz = H[i,:] - gyro_yz_orth
9
10
gyro_xy_m_orth = (np.dot(H[i,:], xy_m_orth)/np.square(xy_norm))*xy_m_orth
11
gyro_xy_m = H[i,:] - gyro_xy_m_orth
12
gyro_xz_m_orth = (np.dot(H[i,:], xz_m_orth)/np.square(xz_norm))*xz_m_orth
13
gyro_xz_m = H[i,:] - gyro_xz_m_orth
14
gyro_yz_m_orth = (np.dot(H[i,:], yz_m_orth)/np.square(yz_norm))*yz_m_orth
15
gyro_yz_m = H[i,:] - gyro_yz_m_orth
16
17
gyro_projections = [gyro_xy, gyro_xz, gyro_yz, gyro_xy_m, gyro_xz_m, gyro_yz_m]
18
#print("Projection of gyro ", i+1, " on planes xyz: ", gyro_projections)
19
20
with open('/Users/path/gyro_config.csv', 'w', newline='') as f:
21
writer = csv.writer(f, delimiter=',')
22
writer.writerows(gyro_projections)
23
Advertisement
Answer
Try to append instead of write mode:
JavaScript
1
2
1
with open('/Users/emanalawadhi/Documents/MBRSCWork/TASKSWork/SSDD/MBZsat/GYRO/gyro_config.csv', 'a', newline='') as f:
2