LoginSignup
4
3

More than 5 years have passed since last update.

[Pythonによる科学・技術計算] 逆行列の計算, numpy

Last updated at Posted at 2017-07-21

numpyを用いて行列の逆行列を計算する。行列オブジェクトにI(Inverseの頭文字)を付けるだけで良い。

例題: 行列Aの逆行列を求める。

import numpy as np
"""
Aの逆行列A^-1を求める
calculate the inverse matrix of A
"""

# 行列Aの生成 make A 
a1_lis = [1, 0, 0]
a2_lis = [0, 2, 0]
a3_lis = [0, 0, 4] 
A_matrix=np.matrix([a1_lis, a2_lis, a3_lis])
##

A_inv_matrix=A_matrix.I  # 逆行列の計算
print(C_matrix)

結果

[[ 3 0 0]
[ 2 4 0]
[ 4 0 16]]


補遺

以下のようにもかける。

A_inv_matrix = np.linalg.inv(A_matrix)
4
3
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
4
3