question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot convert arrays to ndarray

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
deepakkumar1984commented, Apr 8, 2021

Glad it worked, I will have a look into IEnumerable and probably will try to fix that.

On Fri, Apr 9, 2021 at 3:57 AM evo11x @.***> wrote:

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…

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

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

Thanks!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/deepakkumar1984/MxNet.Sharp/issues/41#issuecomment-816042885, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABQJAKM2UFFIWRJ2BV7TAGLTHXYQLANCNFSM42RF5ITQ .

– Regards, Deepak

0reactions
evo11xcommented, Apr 9, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tulipy Cannot convert Series to numpy.ndarray
Tulipy requires numpy as all inputs and outputs are numpy arrays (dtype=np.float64). Yet with data['close'] you are passing a pd.Series . The ...
Read more >
How to convert to/from NumPy
Implicit conversion to NumPy inherits the same restrictions as ak.to_numpy() , namely that variable-length lists cannot be converted to NumPy.
Read more >
Cannot Convert a Symbolic Tensor to a Numpy Array
This is because the numpy() function is designed to convert EagerTensors (which hold actual values) into numpy arrays, not symbolic tensors.
Read more >
Cannot convert <class 'numpy.ndarray'> to TensorType'
It seems like theano is unable to convert cov from a numpy array to a tensor, but in it seems to be the...
Read more >
Cannot convert array to set in java. Getting error
I am solving a leetcode problem in which I have to convert an array into set. My code is class Solution { public...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found