Python learning memo for machine learning by Chainer from Chapter 2

What This is an article that summarizes what I noticed and researched when learning machine learning using Chainer. It is written based on my understanding, so it may be incorrect. I will correct any mistakes.

Today's focus is on learning about lists (arrays)

Content

2. Notes on getting started with Python Continued

list

So-called array. The number of elements is written by len (value) derived from length. The operation (slicing) of extracting only a part of the array can be easily performed.

array[x:y] #x is the starting element, y is the number to be read subsequently y read from x

Designation that said. Both x and y can be omitted. When using a multidimensional array, use it when extracting only a specific array. If it is array, all arrays will be read. For some reason, it doesn't seem to be called a multidimensional list. Simple operation is possible if the value is inserted at the end

array.append(x) #Insert x at the end

tuple

A list (array) whose values cannot be rewritten. Mainly used when dealing with constants collectively. Can the merits be clearly stated? ??

array = (1, 2, 3, 4) #Initialization
array[0] = 1         #The same reading as the list, convenient or inconvenient ...

Mutable / immutable

A word that indicates that the value can be rewritten or not

Dictionary Python can also use key & value sets. For example

array_vector = ('x': 10, 'y': 20, 'z': 30)
array_vector['x'] => 10

You can get each list with keys (), values (), items (). Each return value dict_key, dict_values, dict_items

Control syntax for

Python's control syntax consists of two parts, called the header and the block. Together, they are called compound statements.

And that. further

An iterable object is an object that can return elements one at a time. You can use the built-in function range () to return integers in order as many times as you give the argument. Writing range (5) makes it an iterable object that returns five integers, 0, 1, 2, 3, 4 in sequence.

It seems that the conditional expression in the case of c language is not written but written in the object and given as an iterable object. When giving a list with a variable number of elements as an iterable object

for i in range(len(array)):

If you write, the process will be repeated without excess or deficiency for the number of elements. A highly readable description method is to pass the list itself as an iterable object.

for i in array:

The built-in function ʻenumerate ()is an iterable object that, when passed an iterable object, returns a tuple of(element number, element)` one by one. The variable i becomes a tuple type

for i, j in enumerate(names) #Requires two variables to receive tuple elements

An iterable object that takes multiple iterable objects and returns a pair of their elements in order is zip () zip () returns a tuple in order from the first element of each passed iterable object. The length of this iterable object matches the shortest length of the passed iterable object.

Can it be used when you want to process multiple data at once? ?? ??

Comment Impression that the built-in functions related to the list are substantial. I want to output quickly, but it takes a long time because the learning site is carefully written. Tomorrow, we'll finish learning Python syntax and start learning math. I plan to skip the known content. I remember the markdown a little bit.

Recommended Posts

Python learning memo for machine learning by Chainer from Chapter 2
Python learning memo for machine learning by Chainer Chapter 7 Regression analysis
Python learning memo for machine learning by Chainer Chapter 8 Introduction to Numpy
Python learning memo for machine learning by Chainer Chapter 10 Introduction to Cupy
Python learning memo for machine learning by Chainer Chapter 9 Introduction to scikit-learn
Python learning memo for machine learning by Chainer Chapters 1 and 2
Python learning memo for machine learning by Chainer Chapter 13 Neural network training ~ Chainer completed
Python learning memo for machine learning by Chainer Chapter 13 Basics of neural networks
Python learning memo for machine learning by Chainer until the end of Chapter 2
Python & Machine Learning Study Memo ④: Machine Learning by Backpropagation
Memo for building a machine learning environment using Python
Deep Learning / Deep Learning from Zero 2 Chapter 4 Memo
Deep Learning / Deep Learning from Zero Chapter 3 Memo
Machine learning summary by Python beginners
<For beginners> python library <For machine learning>
Deep Learning / Deep Learning from Zero 2 Chapter 7 Memo
Deep Learning / Deep Learning from Zero 2 Chapter 8 Memo
Interval scheduling learning memo ~ by python ~
Deep Learning / Deep Learning from Zero Chapter 5 Memo
Deep Learning / Deep Learning from Zero Chapter 4 Memo
Deep Learning / Deep Learning from Zero 2 Chapter 3 Memo
"Scraping & machine learning with Python" Learning memo
Deep Learning / Deep Learning from Zero 2 Chapter 6 Memo
Python & Machine Learning Study Memo: Environment Preparation
[Learning memo] Basics of class by python
[Learning memo] Deep Learning made from scratch [Chapter 7]
Amplify images for machine learning with python
Why Python is chosen for machine learning
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]
[Shakyo] Encounter with Python for machine learning
[Python] Web application design for machine learning
A memorandum of scraping & machine learning [development technique] by Python (Chapter 4)
[Memo] Machine learning
Deep learning / Deep learning made from scratch Chapter 7 Memo
A memorandum of scraping & machine learning [development technique] by Python (Chapter 5)
An introduction to Python for machine learning
Python & Machine Learning Study Memo ③: Neural Network
Python & Machine Learning Study Memo ⑥: Number Recognition
[Learning memo] Deep Learning made from scratch [~ Chapter 4]
Python vs Ruby "Deep Learning from scratch" Chapter 2 Logic circuit by Perceptron
Machine learning starting from 0 for theoretical physics students # 1
Python & Machine Learning Study Memo ⑤: Classification of irises
Deep Learning from scratch Chapter 2 Perceptron (reading memo)
Python & Machine Learning Study Memo ②: Introduction of Library
[Python] Collect images with Icrawler for machine learning [1000 images]
Machine learning starting from 0 for theoretical physics students # 2
A memo for creating a python environment by a beginner
progate Python learning memo (updated from time to time)
Python & Machine Learning Study Memo ⑦: Stock Price Forecast
Python class (Python learning memo ⑦)
Python module (Python learning memo ④)
Machine learning course memo
Introduction to Deep Learning for the first time (Chainer) Japanese character recognition Chapter 2 [Model generation by machine learning]
Chapter 6 Supervised Learning: Classification pg212 ~ [Learn by moving with Python! New machine learning textbook]
Python learning notes for machine learning with Chainer Chapters 11 and 12 Introduction to Pandas Matplotlib
Image collection Python script for creating datasets for machine learning
Build an interactive environment for machine learning in Python
Machine learning python code summary (updated from time to time)
Preparing to start "Python machine learning programming" (for macOS)