Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Pass list of Complex to function#2398

pepeluiz8 started this conversation inGeneral
Discussion options

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         }

Any help please?
Thanks.

You must be logged in to vote

Replies: 0 comments

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
General
Labels
None yet
1 participant
@pepeluiz8

[8]ページ先頭

©2009-2025 Movatter.jp