行列のかけ算はnumpyのdotで求めます。
入力
import numpy as np
a = np.array([[4, 1], [2, 3]])
b = np.array([[-3, 5], [1, 2]])
c = np.dot(a, b)
print(c)
出力
[[-11 22]
[ -3 16]]
行列とベクトルのかけ算
ベクトルも1つの行列であり、行列とベクトルのかけ算もdotで求められます。
入力
import numpy as np
a = np.array([[4, 1], [2, 3]])
v = np.array([7, 5])
w = np.dot(a, v)
print(w)
出力
<figure style="padding-bottom: 5px;" class="article-image">
<img src="https://image.rollpie.com/2015/11/business-h2-zukei-01.png"
decoding="async" loading="lazy"
style="width: 320px; height: 28px;"
data-width="700" data-height="60">
<figcaption style="width: 320px;">
<p class="figure-title">business-h2-zukei-01</p>
実際、4×7+1×5=33、2×7+3×5=29となる。