0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

初めに

einsumを使うため、行列の演算を整理しておく。

基本操作

matrix generation

import numpy as np
mat = np.array([[1,2],
                [3,4],
                [5,6]])

array([[1, 2],
       [3, 4],
       [5, 6]])

inverse matrix

mat = np.array([[1,2],
                [3,4],
                ])
mat_inv = np.linalg.inv(mat)

array([[-2. ,  1. ],
       [ 1.5, -0.5]])

pseudo inverser matrix

mat = np.array([[1,2],
                [3,4],
                ])
mat_inv2 = np.linalg.pinv(mat)

array([[-2. ,  1. ],
       [ 1.5, -0.5]])

transpose

mat = np.array([[1,2],
                [3,4],
                ])
mat_t = mat.T
array([[1, 3],
       [2, 4]])

積 Product

element-wise multiplication

matA = np.array([[1, 2], [3, 4]])
matB = np.array([[5, 6], [7, 8]])
print(matA)
print(matB)

[[1 2]
 [3 4]]

[[5 6]
 [7 8]]

matAB = np.multiply(matA, matB)

[[ 5 12]
 [21 32]]

inner product (dot product)

matA_dot_matB = np.dot(matA,matB)

[[19 22]
 [43 50]]

matmul()

matA_matmul_matB = np.matmul(matA, matB)

[[19, 22],
  [43, 50]]

outer product (cross product)

np.cross(matA, matB)
[-4, -4]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?