I've written a function in F# which which uses the KMeans (http://accord-framework.net/docs/html/T_Accord_MachineLearning_KMeans.htm).
A function called compute requires float[][] but I've never seen that in F#. only float[,].
Example of code is below.
let ConverterForCluster =
I create a zero based array of 50 x 50. This will be populated once I interface this with an existing application that returns a float[,], at the moment I'm trying to get to write a converter from [,] to [][]
My distance array is declared as
let mutable Distance = Array2D.zeroCreate 50 50
KMeans is a method from Accord.NET library (link at the top).
let km = KMeans(5)
I'm creating a new variable called dm just so that function Compute of km (below) can accept it. However, using Unchecked.defaultof creates a null array which is the error
let dm : float[][] = Unchecked.defaultof<float[][]>
for i = 0 to 49 do
for j = 0 to 49 do
I believe this conversion from float[,] to float[][] is fine but I've yet to initialise dm so I can't confirm that 100%
dm.[i].[j] <- Convert.ToDouble Distance.[i, j]
This is the function that needs float[][] and won't accept [,]
let label = km.Compute(dm)
label
The exception is:
System.NullReferenceException was unhandled Message: An unhandled exception of type 'System.NullReferenceException' occurred in Cluster.exe Additional information: Object reference not set to an instance of an object.
This error is on the following line
dm.[i].[j] <- Convert.ToDouble Distance.[i, j]
because dm is null due to the line below as I don't know how to initialise it
let dm : float[][] = Unchecked.defaultof<float[][]>
My question is how do I initialise this type of array? And what is the difference?
If I've missed anything from this, please let me know or if it doesn't make sense. Thanks.