- 积分
- 1905
- 明经币
- 个
- 注册时间
- 2022-4-4
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 枫叶棋语 于 2023-3-7 00:59 编辑
需要加载导入pythonnet包,关键在于将Ironpython对象转换成Cpython对象,转换后,就如在Cpython中使用一样。
需要安装Python 3.8,并添加路径
import sys
sys.path.append(r'D:\Pycad\src\packages\pythonnet.3.0.1\lib\netstandard2.0')
sys.path.append(r'D:\Pycad\src\packages\Python.Included.3.11.1\lib\netstandard2.0')
sys.path.append(r'D:\Pycad\src\packages\Python.Deployment.2.0.0\lib\netstandard2.0')
sys.path.append(r'D:\Program Files\Python38')
import clr
clr.AddReference('Python.Runtime.dll')
clr.AddReference('Python.Deployment.dll')
clr.AddReference('Python.Included.dll')
from Python.Runtime import *
from Python.Deployment import *
from Python.Included import *
if not PythonEngine.IsInitialized:
PythonEngine.Initialize()
def CpythonConvertToIron(object):
return eval(object.ToString())
def IronConverToCpython(object):
return PythonEngine.Eval(str(object))
with Py.GIL():
np = Py.Import("numpy")
list1= [[1,2,3],[4,5,6]]
list2=IronConverToCpython(list1)
arr=np.asarray(list2)
最终结果
>>>arr
[[1 2 3]
[4 5 6]]
|
评分
-
查看全部评分
|