This time I would like to briefly summarize the matrix.
As the name implies, it is composed of "rows" and "columns". A concrete example is as follows.
[5, 13]
[4, 6]
[20, 7]
In this case, the "row" is [5,13]. The column refers to [5, 4, 20].
The adjustment of the two matrices can be adjusted between the elements. Specific example) In python, you can define a matrix with numpy's matix function.
>>> A = np.matrix([[5, 13], [4, 6], [20, 7]])
>>> B = np.matrix([[8, 15], [9, 10], [20, 8]])
>>> print(A)
[[ 5 13]
[ 4 6]
[20 7]]
>>> print(B)
[[ 8 15]
[ 9 10]
[20 8]]
>>> C = A + B
>>> print(C)
[[13 28]
[13 16]
[40 15]]
Matrix multiplication is a bit more complicated than adding or subtracting. If what you multiply is simply one real number, you can multiply each element.
>>> print(A)
[[ 5 13]
[ 4 6]
[20 7]]
>>> print(A * 2)
[[10 26]
[ 8 12]
[40 14]]
>>>
However, if it is a matrix that is multiplied by a matrix as shown below, it cannot be simply elements.
>>> print(A)
[[ 5 13]
[ 4 6]
[20 7]]
>>> print(D)
[[1 2]
[3 4]]
>>> print(A * D)
[[44 62]
[22 32]
[41 68]]
>>>
Let's see what we are doing above.
First, look at [5, 13], which is the first row of matrix A. There, the first column of matrix D, [1, 3], is multiplied for each element, and the total is added. Do the same for the second and third rows of matrix A2 and the second column of matrix D. In particular,
[5 * 1 + 13 * 3] = 44
[4 * 1 + 6 * 3] = 22
[20 * 1 + 7 * 3] = 41
[5 * 2 + 13 * 4] = 62
[4 * 2 + 6 * 4] = 32
[20 * 2 + 7 * 4] = 68
[44 62]
[22 32]
[41 68]
In addition, matrix multiplication has the property that if the order of multiplication and multiplication is changed, the value will change.
Recommended Posts