I am using numpy.loadtext
to generate a structured Numpy array from a CSV data file that I would like to save to a MAT file for colleagues who are more familiar
You can do scipy.io.savemat('test.mat', {'mydata': mydata})
.
This creates a struct mydata
with fields foo
and bar
in the file.
Alternatively, you can pack your loop in a dict comprehension:
tmp = {varname: mydata[varname] for varname in mydata.dtype.names}
I don't think creating a temprorary dictionary duplicates data in memory, because Python generally only stores references, and numpy in particular tries to create views into the original data whenever possible.