Chapter 1 Introduction to Python Cut out only the good points of deep learning made from scratch

Python

Python is used in colleges, vocational schools, and computer science classes. It is also used by IT companies such as Google, MS, and FB. If you use machine learning, it's called Python.

Python version

There are 2 series and 3 series. This time I will write everything in 3 series.

External library

Python interpreter

Arithmetic calculation

>>> 1 - 2
-1
>>> 4 * 5
20
>>> 7 / 5
1.4
>>> 3 ** 2
9

Data type

>>> type(10)
int
>>> type(2.718)
float
>>> type('hello')
str

variable

>>> x = 10
>>> print(x)
10
>>> x = 100
>>> y = 3.14
>>> x * y
314.0

list

>>> a = [1,2,3,4,5]
>>> len(a)
5
>>> a[0]
1
>>> a[0:2]
[1,2]
>>> a[1:]
[2,3,4,5]
>>> a[:-1]
[1,2,3,4]

dictionary

>>> me = {'height': 100 }
>>> me['height']
100

Boolean

>>> hungry = True
>>> sleepy = False

if statement

>>> hungry = True
>>> if hungry:
...  print('I'm hungry')
...

for statement

>>> for i in [1,2,3]:

function

>>> def hello():

class

class name
    def __init__(self, xxx, xxx) # constructor
        ...

    def method1 # method1
        ...
    def method2 # method2
        ...

for expample

class Man
    def __init__(self, name)
        self.name = name
        print('init')

    def hello(self):
       print('hello' + self.name)

    def goodbye(self)
       print('goodby' + self.name)

Numpy

import

>>> import numpy as np

You can read numpy as np.

Array generation

>>> x = np.array([1.0,2.0,3.0])
>>> print(x)
[1.2.3.]
>>> type(x)
numpy.ndarray

Calculation

>>> x = np.array([1.0, 2.0, 3.0])
>>> y = np.array([2.0, 4.0, 6.0])
>>> x + y
array([3., 6., 9.])
>>> x- y
array([-1., -2., -3.])
>>> x * y
array([2., 8., 18.])
>>> x / y
array([0.5, 0.5, 0.5])
>>> x = np.array([1.0, 2.0, 3.0])
>>> x/2.0
array([0.5, 1., 1.5])

The number of elements of x and y must be the same

N-dimensional array

>>> A = np.array([[1,2], [2,3]])
>>> print(A)
[
 [1,2]
 [3,4]
]
>>> A.shape
(2,2)
>>> A.dtype
dtype('int64')

>>> B = np.array([3,0], [0,6])
>>> A+B
array([4,2], [3,10])
>>> A*B
array([3,0], [0,24])
>>> print(A)
[[1 2] [3 4]]
>>> A * 10
[[10 20][30 40]]

broadcast

A = np.array([1,2][3,4]) B = np.array([10, 20]) A*B array([10, 40][30, 80])

Access to elements

>>> X = np.array([51,55], [14,19], [0,4])
>>> print(X)
>>> X[0][1]
55
for row in X:
    print(row)

[51 55]
[14 19]
[0 4]

Conversion to a one-dimensional array

X = X.flattern()
[51 55 14 19 0 4]
>>> X[np.array([0, 2, 4])]
array([51, 14, 0])
>>> X > 15
array([T, T, F, T, F, F])
>>> X[X>15]
array([51,55,19])

Matplotlib

Drawing a simple graph

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 6, 0.1)
y = np.sin(x)

plt.plot(x, y)
plt.show() ##Graph drawing

pyplot function

--Multiple graphs can be displayed --Images can also be displayed

Recommended Posts

Chapter 1 Introduction to Python Cut out only the good points of deep learning made from scratch
Chapter 3 Neural Network Cut out only the good points of deep learning made from scratch
Chapter 2 Implementation of Perceptron Cut out only the good points of deep learning made from scratch
Deep Learning from scratch The theory and implementation of deep learning learned with Python Chapter 3
[Learning memo] Deep Learning made from scratch [Chapter 7]
Deep learning / Deep learning made from scratch Chapter 6 Memo
[Learning memo] Deep Learning made from scratch [Chapter 5]
[Learning memo] Deep Learning made from scratch [Chapter 6]
Deep learning / Deep learning made from scratch Chapter 7 Memo
[Learning memo] Deep Learning made from scratch [~ Chapter 4]
Deep Learning from scratch ① Chapter 6 "Techniques related to learning"
Python vs Ruby "Deep Learning from scratch" Chapter 4 Implementation of loss function
Application of Deep Learning 2 made from scratch Spam filter
Python vs Ruby "Deep Learning from scratch" Chapter 3 Graph of step function, sigmoid function, ReLU function
Python vs Ruby "Deep Learning from scratch" Chapter 1 Graph of sin and cos functions
Deep Learning memos made from scratch
[Python] PCA scratch in the example of "Introduction to multivariate analysis"
I read "Reinforcement Learning with Python: From Introduction to Practice" Chapter 1
Write an impression of Deep Learning 3 framework edition made from scratch
From the introduction of JUMAN ++ to morphological analysis of Japanese with Python
I read "Reinforcement Learning with Python: From Introduction to Practice" Chapter 2
Learning notes from the beginning of Python 1
Learning record of reading "Deep Learning from scratch"
Learning notes from the beginning of Python 2
Python vs Ruby "Deep Learning from scratch" Chapter 2 Logic circuit by Perceptron
Good book "Deep Learning from scratch" on GitHub
Deep Learning from scratch Chapter 2 Perceptron (reading memo)
[Learning memo] Deep Learning from scratch ~ Implementation of Dropout ~
[Introduction to Python3 Day 20] Chapter 9 Unraveling the Web (9.1-9.4)
Python vs Ruby "Deep Learning from scratch" Summary
From the introduction of pyethapp to the execution of contract
[Python] [Natural language processing] I tried Deep Learning ❷ made from scratch in Japanese ①
Build a python environment to learn the theory and implementation of deep learning
[Deep Learning from scratch] I implemented the Affine layer
Deep Learning from scratch
Summary from the beginning to Chapter 1 of the introduction to design patterns learned in the Java language
Python points from the perspective of a C programmer
Python Machine Learning Programming Chapter 1 Gives Computers the Ability to Learn from Data Summary
[Chapter 3] Introduction to Python with 100 knocks of language processing
Othello ~ From the tic-tac-toe of "Implementation Deep Learning" (4) [End]
[Chapter 2] Introduction to Python with 100 knocks of language processing
Introduction to Deep Learning for the first time (Chainer) Japanese character recognition Chapter 4 [Improvement of recognition accuracy by expanding data]
[Deep Learning from scratch] I tried to explain Dropout
[Introduction to Python] Basic usage of the library matplotlib
[Chapter 4] Introduction to Python with 100 knocks of language processing
I want to cut out only the face from a person image with Python and save it ~ Face detection and trimming with face_recognition ~
[Deep Learning from scratch] I tried to explain the gradient confirmation in an easy-to-understand manner.
Introduction to Deep Learning for the first time (Chainer) Japanese character recognition Chapter 1 [Environment construction]
"Deep Learning from scratch" Self-study memo (No. 14) Run the program in Chapter 4 on Google Colaboratory
"Deep Learning from scratch" Self-study memo (Part 8) I drew the graph in Chapter 6 with matplotlib
[Deep Learning from scratch] Implementation of Momentum method and AdaGrad method
[Part 4] Use Deep Learning to forecast the weather from weather images
An amateur stumbled in Deep Learning from scratch Note: Chapter 1
[Part 1] Use Deep Learning to forecast the weather from weather images
[Part 3] Use Deep Learning to forecast the weather from weather images
Making from scratch Deep Learning ❷ An amateur stumbled Note: Chapter 5
Introduction to Statistics The University of Tokyo Press Chapter 2 Exercises
An amateur stumbled in Deep Learning from scratch Note: Chapter 3
An amateur stumbled in Deep Learning from scratch Note: Chapter 7
An amateur stumbled in Deep Learning from scratch Note: Chapter 5
Making from scratch Deep Learning ❷ An amateur stumbled Note: Chapter 7