What This is an article that summarizes what I noticed and researched when learning machine learning using Chainer. This time, I will study Numpy.
It is written based on my understanding, so it may be incorrect. I will correct any mistakes, please forgive me.
Content
Algorithms that handle regression analysis, libraries that can conveniently handle multidimensional arrays?
import numpy as np
After reading the text, I couldn't understand the difference between the library and the module, so I looked it up. Reference article below https://qiita.com/yutaro50/items/f93893a2d7b23cb05461 Tensors are handled by array.
a = np.array([1, 2, 3]) #Define a Numpy-style matrix
a.shape => #Output shape as tuple
a.rank => #Output rank
a.size =>#Output size Number of data
a.ndim => #Output len
a = np.zeros((3, 3)) => #3x3 zero matrix
a = np.ones((2, 3)) => #Matrix with all 2x3 elements 1
a = np.full((3, 2), 9) => #A matrix with all 9 3x2 elements
a = np.eye(5) => #5x5 identity matrix
a = np.random.random((4, 5)) => #4x5 with 0 elements~Matrix determined by a random number of 1
a = np.arange(3, 10, 1) => #Row vector increasing by 1 from 3 to 10
a = np[0,3] => #Value in the 1st row and 4th column
#↓ I can't understand this explanation><
#2 x 3 in the middle of the 4 x 5 matrix e=Extract 6 values
center = e[1:3, 1:4]
a[[0, 2, 1], [1, 1, 0]] => # (1, 2), (3, 2), (2, 1)Output the elements of as a row vector
In addition, four arithmetic operations can be performed. Addition and subtraction can be performed even if the matrix shape is different = broadcast On the contrary, unwilling calculation may occur. Caution
Calculation of matrix product AB
np.dot(A,B) or A.dot(B) #Anyway
np.dot(X.T, X) #Calculate the product of the transposed matrix of matrix X and X
np.linalg.inv(A) #Calculate the inverse matrix of matrix A
Note the order as the commutative law generally does not hold
If you have trouble handling the procession, look back here
Comment The content has become difficult, so the update frequency has dropped, but let's do our best
Recommended Posts