-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI_example.py
More file actions
55 lines (39 loc) · 1.22 KB
/
API_example.py
File metadata and controls
55 lines (39 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import numpy as np
import random as rd
import matplotlib.pyplot as plt
import plotparams
#import julia, the api module
import julia
#Set the location for the julia excutable (if need be)
julia.Julia(runtime="C:\\Users\\gabri\\AppData\\Local\\Programs\\Julia-1.5.4\\bin\\julia.exe")
#julia.Main is used to add and access atributes to the julia namespace
#inside Main.eval(), don't need Main.<atribute>, can just access via <attribute>
from julia import Main
#Main.eval() runs julia code.
#Main.using("TextAnalysis") - imports Julia packages needed in .jl if need be
####
#Running julia in python directly
####
#define the data in python
data1=[1,2,3,4,5]
#define the data in the julia-readable object julia.Main
Main.data_j1 = data1
#define a julia function
Main.eval('func(x) = x^2')
#run and return the values back to a python object
out1 = Main.eval("func.(data_j1)")
print("out1 = ", out1)
print("type of out1 = ", type(out1))
####
#Running a julia file in python
####
data2= np.linspace(-100,100,1000)
Main.data_j2 = data2
Main.eval('include("Playground.jl")')
out2 = Main.eval("quad.(data_j2)")
print("out2[0:10] = ", out2[0:10])
print("type of out2 = ", type(out2))
plt.plot(data2, out2)
plt.ylim(0, 10100)
plt.grid()
plt.show()