Introduction to Mathematics Starting with Python Study Memo Vol.1

An introduction to mathematics starting with Python

While reading "Introduction to Mathematics Starting with Python" sold at O'Reilly Japan, I will summarize the points that I was particularly interested in. https://www.oreilly.co.jp/books/9784873117683/

Chapter 1 Dealing with numbers

Handle fractions

The fractions module is available for handling fractions in Python.

fractions_.py


from fractions import Fraction
a = Fraction(1, 2) # Fraction(1, 2)
b = a + 1 + 1.5 # 3.0

Fractions are available in the form of Fraction (numerator, denominator). If there is a floating point in the middle of the expression, the result is returned in floating point. The fractions module supports rational number calculations.

Handle complex numbers

When dealing with complex numbers in Python, use the letters "j" or "J". (In the field of electrical engineering, "i" or "I" is used as a symbol for electric current.) The complex number 1 + 2i is written as 1 + 2j.

complex_.py


a = 1 + 2j
b = complex(3, 4) # (3+4j)

a + b # (4+6j)
a - b # (-2+2j)

a.real #1 Real part
a.imag #2 imaginary part

c = a.conjugate() # (1-2j)Conjugate complex number
d = abs(a) # 2.23606797749979 Complex size

Complex numbers can be defined using the complex () function. It can be defined by assigning variables such as complex (x, y). A conjugate complex number is a complex number that has the same real part and the opposite sign of the imaginary part. It can be obtained using the conjugate () method. The magnitude of a complex number can be determined by the abs () function. A real number returns an absolute value, but a complex number returns a magnitude.

cmath You can use other functions that handle complex numbers by using the module.

cmath_.py


from cmath import *
a = 1 + 1j
phase(a) # 0.7853981633974483 Returns the argument in floating point. The return value is[-π, π]Range of.
polar(a) # (1.4142135623730951, 0.7853981633974483)It can be converted from Cartesian coordinates to polar coordinates.(x, y) → (r, Θ)

Recommended Posts

Introduction to Mathematics Starting with Python Study Memo Vol.1
Convert memo at once with Python 2to3
Memo to ask for KPI with python
"System trade starting with Python3" reading memo
[Introduction to Python] Let's use foreach with Python
[Python] Introduction to CNN with Pytorch MNIST
[Python] Easy introduction to machine learning with python (SVM)
Introduction to Artificial Intelligence with Python 1 "Genetic Algorithm-Theory-"
Markov Chain Chatbot with Python + Janome (1) Introduction to Janome
Markov Chain Chatbot with Python + Janome (2) Introduction to Markov Chain
Introduction to Artificial Intelligence with Python 2 "Genetic Algorithm-Practice-"
Introduction to Tornado (1): Python web framework started with Tornado
Python & Machine Learning Study Memo ②: Introduction of Library
Introduction to formation flight with Tello edu (Python)
Introduction to Python with Atom (on the way)
Introduction to Generalized Linear Models (GLM) with Python
[Introduction to Udemy Python3 + Application] 9. First, print with print
Introduction to Python language
Introduction to OpenCV (python)-(2)
Python starting with Windows 7
GRPC starting with Python
Memo to create your own Box with Pepper's Python
A memo connected to HiveServer2 of EMR with python
[Introduction to Python] How to iterate with the range function?
Discord Bot with recording function starting with Python: (1) Introduction discord.py
[Chapter 5] Introduction to Python with 100 knocks of language processing
An introduction to Python distributed parallel processing with Ray
Reading Note: An Introduction to Data Analysis with Python
[Chapter 3] Introduction to Python with 100 knocks of language processing
[Python] A memo to write CSV vertically with Pandas
[Chapter 2] Introduction to Python with 100 knocks of language processing
I tried to solve the problem with Python Vol.1
[Chapter 4] Introduction to Python with 100 knocks of language processing
Introduction to Python Django (2) Win
Twitter graphing memo with Python
Connect to Wikipedia with Python
Post to slack with Python 3
Reinforcement learning starting with Python
Introduction to RDB with sqlalchemy Ⅰ
Introduction to serial communication [Python]
Switch python to 2.7 with alternatives
Write to csv with Python
[Introduction to Python] <list> [edit: 2020/02/22]
Introduction to Python (Python version APG4b)
An introduction to Python Programming
Python starting with Hello world!
Introduction to Python For, While
Introduction to her made with Python ~ Tinder automation project ~ Episode 6
20200329_Introduction to Data Analysis with Python Second Edition Personal Summary
Introduction to her made with Python ~ Tinder automation project ~ Episode 5
Getting Started with Mathematics Starting with Python Programming Challenges Personal Notes-Problem 1-1
Introduction to Python for VBA users-Calling Python from Excel with xlwings-
[Raspi4; Introduction to Sound] Stable recording of sound input with python ♪
[Introduction to Python] How to get data with the listdir function
[Introduction to Udemy Python3 + Application] 51. Be careful with default arguments
[Introduction to Udemy Python 3 + Application] 58. Lambda
[Introduction to Udemy Python 3 + Application] 31. Comments
Python: How to use async with
IPynb scoring system made with TA of Introduction to Programming (Python)
Link to get started with python
Introduction to Python Numerical Library NumPy