[英]How to import Julia packages into Python
可以使用juliacall
包使用 Julia 的内置模块和函数。 例如:
>>> 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'>
然后我很想知道是否可以将已安装的 julia 包导入 Python? 例如,假设有人想将Flux.jl
导入 Python。 有没有办法做到这一点?
我是通过juliacall
GitHub 页面的第二个示例的图片找到的。 根据示例,我可以通过以下步骤导入Flux.jl
:
>>> from juliacall import Main as jl
>>> jl.seval("using Flux")
此外,可以在 Python 中使用Pkg
安装任何已注册的 Julia 包:
>>> from juliacall import Main as jl
>>> jl.Pkg.add("Flux")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.