Calling Python functions and Python modules (example of how to write)
note22
◆ Calling Python functions
#Declaring and getting Python functions(max function)
pymax = py"max"
#Execution of Python function
pymax([1, 2, 3])
◆ Use of Python module
#Call Python's math library with pyimport function
pymath = pyimport("math")
#Math in python.Run pi
pymath.pi
Commentary
You can call and execute Python functions from Julia, or import and execute Python modules (Python's import function).
(1) Installation of PyCall.jl
Use PyCall.jl to execute and call Python in Julia.
Install in package management mode.
In the interactive execution environment, press] in square brackets to enter package mode.
Type add PyCall
to install the package.
When the installation is complete, press the "Backspace" key to cancel the package mode.
(2) Calling a Python function
To execute or call a Python function, first load the PyCall module with the following command.
using PyCall
To execute a Python function, declare and get the Python function with the string "py".
Execute by calling the declared character string.
(3) Use of Python module
To use a library that you import and call in Python, such as math or numpy, use the pyimport function.
Table of contents
Julia Quick Look Note [01] How to use variables and constants
Julia Quick Look Note [02] Arithmetic Expressions, Operators
[Julia Quick Note [03] Complex Numbers]
(https://qiita.com/ttabata/items/225c77a4d71fafc3e482)
Julia Quick Look Note [04] Regular Expression
....
Open lottery
[Julia quick note [05] if statement]
(https://qiita.com/ttabata/items/4f0bcff1e32f60402dfb)
[Julia fast-drawing note [06] loop processing]
(https://qiita.com/ttabata/items/2a53825101b0b75fb589)
[Julia Quick Note [07] try, catch, finally]
(https://qiita.com/ttabata/items/1d6fe990526c99b65b5f)
[Julia Quick Look Note [08] Variable Types (Int, Float, Bool, Char, String)]
(https://qiita.com/ttabata/items/2b84a826e39bfe432b62)
[Julia Quick Look Note [09] Function (1) Basics]
(https://qiita.com/ttabata/items/d9b4f2728ec0dbcc6394)
[Julia Quick Look Note [10] Function (2) Application]
(https://qiita.com/ttabata/items/462e216c43d519f1969d)
[Julia fast-drawing notebook [11] Nothing type]
(https://qiita.com/ttabata/items/0e5a6b21968d8752cf0b)
[Julia Quick-Draw Note [12] Composite Type]
(https://qiita.com/ttabata/items/27469216a3c33101c825)
[Julia Fast-Drawing Note [13] Tuple]
(https://qiita.com/ttabata/items/ebe35dbfec4efbc1c29a)
[Julia Quick Note [14] List (Array type one-dimensional array)]
(https://qiita.com/ttabata/items/7528863ccbb282e8260d)
[Julia Quick Look Note [15] Dictionary]
(https://qiita.com/ttabata/items/77a4f1d02b51d067bfb7)
[Julia quick note [16] set]
(https://qiita.com/ttabata/items/ca8137922a785122037e)
[Julia Quick Note [17] Multidimensional Array (1) Initialization]
(https://qiita.com/ttabata/items/01fecbd14363460a27a6)
[Julia Quick Look Note [18] Multidimensional Array (2) Various Operations and Functions]
(https://qiita.com/ttabata/items/f35896a5fa005fba7fbc)
[Julia Quick Look Note [19] Multidimensional Array (3) Subarray]
(https://qiita.com/ttabata/items/045c00406fe45270b42e)
[Julia quick note [20] file input / output]
(https://qiita.com/ttabata/items/5a99c3998060d161ace8)
[Julia quick note [21] JSON, XML file input / output]
(https://qiita.com/ttabata/items/65ebec11830271f9be71)
[Julia quick note [22] Calling Python functions and Python modules]
(https://qiita.com/ttabata/items/3afc8cef40d1e98a7b17)
[Julia quick-draw note [23] Graph drawing with Matplotlib in Julia]
(https://qiita.com/ttabata/items/96a0e172addfac690cca)
(* We will continue to increase the content)
Related information
: paperclip: Julia --Official page
https://julialang.org/
: paperclip: Julia --Japanese official document
https://julia-doc-ja.readthedocs.io/ja/latest/index.html
: paperclip: First time Julia and installation (Windows & Linux)
https://qiita.com/ttlabo/items/b05bb43d06239f968035
:paperclip: Julia - Mathematics
https://docs.julialang.org/en/v1/base/math/
Opinions etc.
If you have any opinions or corrections, please let us know.