第2章準備
2.3.3. Matrices2.3.3 行列
Just as scalars are -order tensors and vectors are -order tensors, matrices are -order tensors. We denote matrices by bold capital letters (e.g., , , and ), and represent them in code by tensors with two axes. The expression indicates that a matrix contains real-valued scalars, arranged as rows and columns. When , we say that a matrix is square. Visually, we can illustrate any matrix as a table. To refer to an individual element, we subscript both the row and column indices, e.g., is the value that belongs to ’s row and column:
英語のヒント
スカラーが階のテンソルで、ベクトルが階のテンソルであるのと同じように、行列は階のテンソルである。行列は太字の大文字(たとえば、、)で表し、コードでは軸が二つのテンソルで表す。式は、行列が、行列に並んだ個の実数値のスカラーを含むことを示す。のとき、その行列は正方行列であるという。見た目のうえでは、どんな行列も表として描ける。個々の要素を指すには、行と列の両方のインデックスを添え字に付ける。たとえばは、の行列に属する値である。
(2.3.2)
In code, we represent a matrix by a -order tensor with shape (, ). We can convert any appropriately sized tensor into an matrix by passing the desired shape to
reshape:英語のヒント
コードでは、行列を、形状が(, )の階のテンソルで表す。
reshapeに望む形状を渡せば、適切な大きさののテンソルをの行列に変換できる。A = torch.arange(6).reshape(3, 2)
Atensor([[0, 1],
[2, 3],
[4, 5]])Sometimes we want to flip the axes. When we exchange a matrix’s rows and columns, the result is called its transpose. Formally, we signify a matrix ’s transpose by and if , then for all and . Thus, the transpose of an matrix is an matrix:
英語のヒント
軸を入れ替えたいこともある。行列の行と列を入れ替えた結果を、その転置という。形式的には、行列の転置をで表し、なら、すべてのとについてである。したがって、の行列の転置はの行列である。
(2.3.3)
In code, we can access any matrix’s transpose as follows:
英語のヒント
コードでは、どんな行列の転置も次のように得られる。
A.Ttensor([[0, 2, 4],
[1, 3, 5]])Symmetric matrices are the subset of square matrices that are equal to their own transposes: . The following matrix is symmetric:
英語のヒント
対称行列とは、正方行列のうち、自分自身の転置に等しいもの、つまりであるものである。次の行列は対称である。
A = torch.tensor([[1, 2, 3], [2, 0, 4], [3, 4, 5]])
A == A.Ttensor([[True, True, True],
[True, True, True],
[True, True, True]])Matrices are useful for representing datasets. Typically, rows correspond to individual records and columns correspond to distinct attributes.
英語のヒント
行列はデータセットを表すのに便利である。普通、行は個々のレコードに、列は異なる属性に対応する。