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 3 years have passed since last update.

ベクトル演算 (python,numpy)

Last updated at Posted at 2021-07-16

0. 前処理

$d=3$として

import numpy as np
x=np.array([1,2,3])
y=np.array([4,5,6])
z=np.array([7,8,9])
s=np.array([x,y,z])

とします.

1. 内積(inner product)

x,y\in\mathbb{R}^d,<x,y>=x^{\rm T}y=\sum^{n}_{i=1}x_iy_i
np.dot(x,y),x@y
>> (32,32)

2. 内積の逆(正式名称知りません)

x,y\in\mathbb{R}^d,xy^{\rm T}_{i,j}=x_iy_j,xy^{\rm T}\in\mathbb{R}^{d\times d}
np.outer(x,y)
>>  array([[ 4,  5,  6],
           [ 8, 10, 12],
           [12, 15, 18]])

3. その他

from numpy import linalg as LA
# 二次形式
x@s@x==228
>> True
# lp-ノルム
p=2
LA.norm(x,ord=p)==3.7416573867739413
>> True
# 無限のるむ
np.max(x)==3
>> True
# 行列式
LA.det(s)==0.0
>> True
# 逆行列
try:
     LA.inv(s)
except LA.LinAlgError:
     print('not singular matrix')
>> not singular matrix
# フロベニウスノルム
LA.norm(s,'fro')==16.881943016134134
>> True
# 行列のpノルム
p=1
LA.norm(s,ord=p)==18.0
>> True
# 行列の無限ノルム
np.max(s)==9
>> True
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?