SciSharp / NumSharp

High Performance Computation for N-D Tensors in .NET, similar API to NumPy.
https://github.com/SciSharp
Apache License 2.0
1.34k stars 188 forks source link

how to make NumSharp.NDArray from Numpy.NDarray? #416

Open djagatiya opened 4 years ago

djagatiya commented 4 years ago

I found a solution, but is this the right way to do it?

Numpy.NDarray numpyArray = Numpy.np.random.randn(224,224,3);
byte[] v = numpyArray.GetData<byte>();
fixed (byte* packet = v)
{
    var block = new UnmanagedMemoryBlock<byte>(packet, v.Length);
    var storage = new UnmanagedStorage(new ArraySlice<byte>(block), numpyArray.shape.Dimensions);
    NumSharp.NDArray numSharpArray = new NumSharp.NDArray(storage);
}