Last active
June 2, 2021 23:24
-
-
Save benjaminrose/6fc4025d871077793a8d to your computer and use it in GitHub Desktop.
This is an useful example of how I like to save my data using numpy and savetxt.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
#create random data | |
data1 = np.random.rand(10) | |
data2 = np.random.rand(10) | |
data3 = np.random.rand(10) | |
#stack data into one ojbect | |
data_list = np.dstack((data1, data2, data3)) | |
#set up file metadata | |
filename = 'data.csv' | |
header = '''Data from awsome science | |
data1, data2, data3 | |
(cm), (ft), (lbs)''' #don't have tabs here, they will show up in the header. | |
#saving data | |
np.savetxt(filename, data_list[0], delimiter=',', header=header) | |
#data still needs one wraper around it, but after dstack it had an extra. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I should probably just use: