Reading (and Writing) multiple Matrices to a stream in MathNet

30 views Asked by At

I have an array of MathNet matrices, and I want to write them to a single file and also read them back as multiple matrices.

When I try and read them from files it always throws an invalid string format error from the DelimitedReader.Read method.

I've tried using different file formats (csv, txt), I've also tried using different and default delimiters.

I can't seem to find any in depth/intensive documentation for the MathNet.Numerics.Data which would explain how to handle this situation.

EDIT: it appears that the reader cannot tell where each matrix is separated, is there a way I can get around this?

Code for writer:

using (StreamWriter streamWriterWeights = new StreamWriter("Weights" + Loader.FormatFileName(fileName, typeof(NNBrain), ".csv"), false))
                {
                    foreach (Matrix<double> weightMatrix in Weights)
                    {
                        DelimitedWriter.Write<double>(streamWriterWeights, weightMatrix, delimiter: ",");
                    }
                }

Code for reader:

 using (StreamReader streamReaderWeights = new StreamReader("Weights" + Loader.FormatFileName(fileName, typeof(NNBrain), ".csv")))
                {
                    for (int i = 0; i < Weights.Length; i++)
                    {
                        Weights[i] = DelimitedReader.Read<double>(streamReaderWeights, delimiter: ",");
                    }
                }
0

There are 0 answers