deepakkumar1984 / MxNet.Sharp

.NET Standard bindings for Apache MxNet with Imperative, Symbolic and Gluon Interface for developing, training and deploying Machine Learning models in C#. https://mxnet.tech-quantum.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot convert arrays to ndarray

evo11x opened this issue · comments

When I try to convert any array to ndarray I get this error:

System.ArgumentException: 'Object contains non-primitive or non-blittable data.'

and I get the error in the new NDArray

var ctx = mx.Cpu();
float[][] labels= training_labels.ToArray(); // [1000][1]
var train_y1 = new NDArray(labels, new Shape(labels.Count(), 1), ctx: ctx, DType.Float16);

Is there a way to convert List of array of floats to NDArray ?

Thanks!

You need to pass like this
float[] labels= training_labels.ToArray();

I will make a sample app, you are right with float[] labels it works, but the training data is an array of 17 columns with 100 numbers each, float[17][100], and I get the same error with that.

With this code I got the error

IList<IList<float[]>> training_data = training.Select(v => v.GetFeatures()).ToList();
var x = new NDArray(training_data.ToArray(), new Shape(100, 17));

Now I have changed as you said to simple array and it looks like it works...but the NDArray converted the array to 1D data, I hope it's ok for training

float[,,] training_data = new float[1000, 17, 100];
var x = new NDArray(training_data, new Shape(100, 17, 1000));

You have any ideea why IList / IEnumerable.ToArray does not work?

Thanks!

Is there an NDArray function to add elements? or change values of the array? I still having problems copying the 3D array to float[,,] and it would be useful to create the NDArray directly from my list of arrays without creating a float[,,] first.