Fsharp: Read csv into matrix

Feb 9 at 2:38 PM
Hi,

I'm new to FSharp and Math.Net Numerics.

I have a csv file with float numbers and headers such as:

A,B,C
0.5,0.6,98.0
2.0,3.4,5.3

And I'd like to create a matrix from this input.

I thought maybe MathNet.Numerics.Data.Text would be right package to do this but I can't find any documentation about it.

Any suggestions how to tackle this would be appreciated.

BTW: I also tried the F# csv type provider. I can load the data alright, but then I don't know how to convert them to a matrix.

Regards
Radibor
Coordinator
Feb 9 at 3:43 PM
Edited Feb 9 at 3:46 PM
Hi

With the "MathNet.Numerics.Data.Text" and "System.Globalization" namespaces open, try:
let matrix = DelimitedReader.ReadFile<float>("data.csv", false, ",", true, CultureInfo.InvariantCulture)
In addition to ReadFile there is also Read to read from a TextReader (e.g. a StringReader if you have the content already as string) and ReadStream to read from a stream.

Thanks,
Christoph
Marked as answer by cdrnet on 2/9/2014 at 11:00 AM
Coordinator
Feb 9 at 5:43 PM
Just added at least very basic documentation: http://numerics.mathdotnet.com/docs/CSV.html

Thanks,
Christoph
Feb 9 at 8:00 PM
Hello Christoph,

Thank you very much for your quick reply and the documentation! Just what I was looking for.

Regards
Radibor