我找到了一个 Julia 函数,可以很好地完成我需要的工作。如何快速集成它以便能够从 Python 调用它?
假设函数是
f(x,y) = 2x.+y
Run Code Online (Sandbox Code Playgroud)
从 Python 中使用它的最佳和最优雅的方法是什么?
人们可以通过该包来使用 Julia 的内置模块和函数juliacall。例如:
>>> from juliacall import Main as jl
>>> import numpy as np
# Create a 2*2 random matrix
>>> arr = jl.rand(2,2)
>>> arr
<jl [0.28133223988783074 0.22498491616860727; 0.008312971104033062 0.12927167014532326]>
# Check whether Numpy can recognize the shape of the array or not
>>> np.array(arr).shape
(2, 2)
>>> type(np.array(arr))
<class 'numpy.ndarray'>
Run Code Online (Sandbox Code Playgroud)
然后我很好奇是否可以将已安装的 julia 包导入到 Python 中?例如,假设有人想要导入Flux.jl到 Python 中。有办法实现这一点吗?