Last active
August 14, 2019 12:23
-
-
Save hhachiya/22da1870e447e7ce30dd0b684fb0a17a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# 数値計算用のライブラリnumpyをnpとしてインポート | |
import numpy as np | |
# 3x3のnumpy配列(行列) | |
W = np.array([ [1,0,0], [0,1/2,0], [0,0,1/3] ]) | |
H = np.array([ [1,0,0], [0,2,0], [0,0,3] ]) | |
print(f"W:\n{W}\nH:\n{H}\n") | |
# 3x1のnumpy配列(ベクトル) | |
x = np.array([ [1], [2], [3] ]) | |
b = np.array([ [1], [2], [3] ]) | |
print(f"x:\n{x}\nb:\n{b}\n") | |
# 逆行列の計算 | |
W_inv = np.linalg.inv(W) | |
print(f"W_inv:\n{W_inv}\n") | |
# 行列W_invの転置とベクトルxの掛け算とbとの足し算 | |
W_inv_transpose = W_inv.T | |
f_x = np.matmul(W_inv_transpose,x) | |
f_x = f_x + b | |
print(f"W_inv_transpose:\n{W_inv_transpose}\n") | |
print(f"f_x:\n{f_x}\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment