Python Method to save Matrix Dict to a file
- 2021-01-14 06:05:44
- OfStack
This is as follows:
>>> import numpy
>>> mat = numpy.matrix("1 2 3; 4 5 6; 7 8 9")
>>> mat.dump("my_matrix.dat")
>>> mat2 = numpy.load("my_matrix.dat")
When Python processes csv files, it is often used to say that the whole csv file is read into an array or matrix. With the help of the numpy package, the following code can be used for simple, efficient and low implementation:
import numpy
my_matrix = numpy.loadtxt(open("c:\\1.csv","rb"),delimiter=",",skiprows=0)
Storing an array or matrix as an ES11en file can be done using the following code:
numpy.savetxt('new.csv', my_matrix, delimiter = ',')