5

One can use Julia's built-in modules and functions using the juliacall package. for example:

>>> 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'>

Then I'm curious to know if importing an installed julia package into Python is possible? For example, let's say that one wants to import Flux.jl into Python. Is there a way to achieve this?

Shayan
  • 5,165
  • 4
  • 16
  • 45

1 Answers1

3

I found it through scrutinizing the pictures of the second example of the juliacall GitHub page. According to the example, I'm able to import Flux.jl by taking these steps:

>>> from juliacall import Main as jl
>>> jl.seval("using Flux")

Also, one can install any registered Julia package using Pkg in Python:

>>> from juliacall import Main as jl
>>> jl.Pkg.add("Flux")
Shayan
  • 5,165
  • 4
  • 16
  • 45