- Notifications
You must be signed in to change notification settings - Fork750
-
Environment
Details
I am experiencing issues while converting the nd.ndarray(dtype=int) via (long[])result[0]
The nd.ndarray(dtype=float) via (double[])result[1] works as a charme. My current workaround is iterating over the nd.ndarray(dtype=int) with the size of the result array by calling ToArrayByIteration() Am I missing something?
Problematic here is converting "indices" from dtype=int to long in C#. The datatype of the result in C# in Debug view seems to be Int64. @staticmethoddefmethod(rate:int,data:np.ndarray)->Tuple[np.ndarray,np.ndarray]:ds=int(rate)indices=np.arange(len(data),dtype=int)result_data=np.array(data,dtype=float)n=len(indices )indices=indices [:n*ds:ds]result_data=result_data [:n*ds].reshape(n,ds).mean(axis=1)returnindices ,result_data Returning dtype=float is not intended but works with the same conversion to double. @staticmethoddefmethod(rate:int,data:np.ndarray)->Tuple[np.ndarray,np.ndarray]:ds=int(rate)indices=np.arange(len(data),dtype=float)result_data=np.array(data,dtype=float)n=len(indices )indices=indices [:n*ds:ds]result_data=result_data [:n*ds].reshape(n,ds).mean(axis=1)returnindices ,result_data I left out initialising pythonengine and loading the module in this case. publicclassWrapper{public(long[]x,double[]y)ExecutePythonMethod(intrate,List<double>data){usingvar_=Py.GIL();varresult=_module.class.method(rate,data);varx=PythonDataConverter.ToArrayByIteration<long>(result[0]);vary=PythonDataConverter.ToArray<double>(result[1]);return(x,y);}}publicstaticclassPythonDataConverter{publicstaticT[]ToArrayByIteration<T>(dynamicarrayFromPython){varsize=(long)arrayFromPython.size;vararray=newT[size];for(vari=0;i<size;i++){array[i]=(T)arrayFromPython[i];}returnarray;}publicstaticT[]ToArray<T>(dynamicarrayFromPython){return(T[])arrayFromPython;}} |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 0 comments
This discussion was converted from issue #2407 on July 01, 2024 17:54.