第2章準備
2.3.10. Matrix–Matrix Multiplication2.3.10 行列と行列の積
Once you have gotten the hang of dot products and matrix–vector products, then matrix–matrix multiplication should be straightforward.
英語のヒント
内積と、行列とベクトルの積のこつがつかめたら、行列どうしの積は簡単なはずである。
Say that we have two matrices and :
英語のヒント
二つの行列とがあるとしよう。
(2.3.7)
Let denote the row vector representing the row of the matrix and let denote the column vector from the column of the matrix :
英語のヒント
が行列の行目を表す行ベクトル、が行列の列目からとった列ベクトルを表すとしよう。
(2.3.8)
To form the matrix product , we simply compute each element as the dot product between the row of and the column of , i.e., :
英語のヒント
行列の積を作るには、各要素を、の行目との列目の内積、つまりとして計算すればよい。
(2.3.9)
We can think of the matrix–matrix multiplication as performing matrix–vector products or dot products and stitching the results together to form an matrix. In the following snippet, we perform matrix multiplication on
A and B. Here, A is a matrix with two rows and three columns, and B is a matrix with three rows and four columns. After multiplication, we obtain a matrix with two rows and four columns.英語のヒント
行列どうしの積は、回の行列とベクトルの積、あるいは回の内積を行い、その結果をつなぎ合わせての行列を作ることと考えられる。次のコードの断片では、
AとBの行列の積を計算する。ここでAは2行3列の行列、Bは3行4列の行列である。掛け合わせると、2行4列の行列が得られる。B = torch.ones(3, 4)
torch.mm(A, B), A@B(tensor([[ 3., 3., 3., 3.],
[12., 12., 12., 12.]]),
tensor([[ 3., 3., 3., 3.],
[12., 12., 12., 12.]]))The term matrix–matrix multiplication is often simplified to matrix multiplication, and should not be confused with the Hadamard product.
英語のヒント
行列どうしの積という言葉は、しばしば行列の積と簡略化される。アダマール積と混同してはならない。