Julia Quick Note [22] Calling Python functions and Python modules

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. image.png 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 image.png To execute a Python function, declare and get the Python function with the string "py". Execute by calling the declared character string. image.png

(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. image.png

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.

Recommended Posts

Julia Quick Note [22] Calling Python functions and Python modules
Note for Pyjulia calling Julia from Python
Python packages and modules
Julia Quick Note [01] How to use variables and constants
Julia Quick Note [03] Complex Numbers
Julia Quick Note [06] Loop processing
Julia Quick Note [10] Function (2) Application
Julia quick note [05] if statement
Understand Python packages and modules
Julia Quick Note [04] Regular Expression
Python 3 sorted and comparison functions
Julia Quick Note [09] Function (1) Basics
Python higher-order functions and comprehensions
About python dict and sorted functions
Introductory Python Modules and conditional expressions
Python Basic Course (14 Modules and Packages)
Julia Quick Note [02] Arithmetic formulas, operators
Modules and packages in Python are "namespaces"
[Python] Package and distribute your own modules
Python functions
Note: Python
Learn python functions, arguments, scopes, return values, modules and libraries with progate
Python note
Use Python and MeCab with Azure Functions
Correspondence between Python built-in functions and Rust
A note on optimizing blackbox functions in Python
Practice applying functions and global variables in Python
Solving the Lorenz 96 model with Julia and Python
[Note] Installing Python 3.6 + α on Windows and RHEL
A story about modifying Python and adding functions
cv2 functions and data types (OpenCV python bindings)
Astro: Python modules / functions often used for analysis
Python study note_002
Note: Python Decorator
[Python] Learning Note 1
Python study note_004
Python quick start
Python study note_003
#Python basics (functions)
[Beginner] Python functions
[Note] openCV + python
Python Easy-to-use functions
Python beginner's note
Python basics: functions
[Python for Hikari-] Chapter 06-04 Functions (arguments and return value 3)
Mayungo's Python Learning Note: List of stories and links
Implemented List and Bool in Python and SQLite3 (personal note)
A quick comparison of Python and node.js test libraries
[Python for Hikari-] Chapter 06-01 Functions (Intrinsic Functions and Function Definitions)
A note on handling variables in Python recursive functions
[Python for Hikari-] Chapter 06-03 Functions (arguments and return value 2)
Get an abstract understanding of Python modules and packages
Note calling the CUDA Driver API with Python ctypes