I am trying to save a list sigma1 containing a numpy array in CSV format. In the current output, the data is saved in multiple rows without commas. In the expected output, I want the data to be saved in a single row with commas, exactly like sigma1.
import numpy as np
import csv
sigma1= [np.array([[0.02109],
[0.02109],
[0.02109],
[0.02109],
[0.02109],
[0.02109],
[0.02109],
[0.02109],
[0.02109],
[0.02109],
[0.02109],
[0.02109]])]
with open('Data_sigma.csv', 'w') as f:
writer = csv.writer(f)
print(sigma1)
f.writelines('sigma'+ '\n')
f.write(str(sigma1))
The current output is
The expected output is


np.array) i.e.[0.02109],[0.02109],[0.02109],[0.02109],[0.02109],[0.02109],[0.02109],[0.02109],[0.02109],[0.02109],[0.02109],[0.02109]