In Python, I would like to store numpy arrays, matrices and possibly later other objects in plain text format.
My idea was to use ConfigParser and define parser array2string, matrix2string, string2array and string2matrix (there is numpy.array2string and matrix2string could be implemented based on that, but I couldn't find functions for the reverse). Then writing looks like:
config.set('calibration', 'center', array2string(center))
config.set('calibration', 'trans_matrix', matrix2string(trans_matrix))
and reading like:
center = string2array(config.get('calibration', 'center'))
trans_matrix = string2matrix(config.get('calibration', 'trans_matrix'))
What is the best way to write and read the numpy objects?
array2string, but I cannot findstring2array,matrix2stringandstring2matrix. From which package are these functions?array2string,matrix2string,string2arrayandstring2matrixare placeholders for the functions to be implemented.numpy.savetxtandnumpy.loadtxtwrite to files and not strings and can't be used to write multiple arrays to a file. I couldn't find reverse functions fornumpy.array2stringand the like.savetxtto save an array into a temporary file, read it as a string and remove the file after. Seriously, numpy provides a lot of useful methods. Have you tried them? Also there ispicklein standard Python library.pickleright now but it does not save the objects in plain text. I thought that there maybe is an elegant solution to it (especially one that writes and reads from strings and therefore allows me to use ConfigParser). I guess I'll usenumpy.array2stringfor writing arrays and matrices and write the string2 parsers myself.