I want to save some histogram data in a csv file. This is the code I came up with:
ExportName_csv = 'ExportData/' + FileName + '.csv'
freq, bins = np.histogram(ValList,bins)
np.savetxt(ExportName_csv, izip(freq, bins), delimiter="\t")
For each bin I want to save the bin value and the corresponding count freq in ExportName_csv. I want values regarding different to be bins in different lines; in each line values are separated by a comma.
With the current code I get the error IndexError: tuple index out of range. What do you suggest to do?
Full traceback is:
np.savetxt(ExportName_csv, izip(freq, bins), delimiter="\t")
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/lib/npyio.py", line 976, in savetxt ncol = X.shape[1]
IndexError: tuple index out of range
First, comma is ',', not \t.
Second, you should use zip, not izip:
>>> data = zip(*np.histogram(ValList,bins))
>>> np.savetxt('test.txt', data, delimeter=',')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With