Exemplo n.º 1
0
        public static unsafe NDarray ToNumpyNET(this NDArray nd)
        {
            using (Py.GIL()) {
                if (NumpyInteropScope == null)
                {
                    NumpyInteropScope = Py.CreateScope();
                    NumpyInteropScope.ExecResource("numpy_interop.py");
                    NumpyConverter = NumpyInteropScope.GetFunction("to_numpy");
                }

                return(new NDarray(NumpyConverter.Invoke(new PyLong((long)nd.Unsafe.Address),
                                                         new PyLong(nd.size * nd.dtypesize),
                                                         new PyString(nd.dtype.Name.ToLowerInvariant()),
                                                         new PyTuple(nd.shape.Select(dim => (PyObject) new PyLong(dim)).ToArray()))));
            }
        }