You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
Im trying to execute a python function with parameters.
The Python code:
def myComplexOperation(signal):
import numpy as np
a = np.array(arg1)
return a*2
C# Code
Runtime.PythonDLL = @"C:\Python38\python38.dll";
var pathToVirtualEnv = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\venv"));
Console.WriteLine(pathToVirtualEnv);
string additional = $"{pathToVirtualEnv};{pathToVirtualEnv}\\Lib\\site-packages;{pathToVirtualEnv}\\Lib";
PythonEngine.PythonPath = PythonEngine.PythonPath + ";" + additional;
Console.WriteLine(PythonEngine.PythonPath);
PythonEngine.Initialize();
PythonEngine.BeginAllowThreads();
List<object> objParams = new List<object>();
objParams.Add(1+2j); // Complex
objParams.Add(2+3j); // Complex
PyList myPyLst = new PyList();
for (int nPos = 0; nPos < objParams.Count; nPos++)
{
myPyLst.Append(objParams[nPos]);
}
PyObject[] pyParams = new PyObject[2];
pyParams[i] = myPyLst
var locals = new PyDict();
PythonEngine.Exec(cmd, null, locals);
var execFunc = locals.GetItem("myComplexOperation");
using (Py.GIL())
{
PyObject result;
result = execFunc.Invoke(pyParams);
// here is the problem:
// The code works when parameter is String (PyString), Integer (PyInt or PyFloat), PyList (strings, numerics)
// but not working when using a PyList with Complex number for Numpy operations.
// The return is empty
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
Im trying to execute a python function with parameters.
The Python code:
C# Code
Any help please?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions