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
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
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 ...
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
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