プリンキピア

第2章準備

2.3.3. Matrices2.3.3 行列

Just as scalars are 0th-order tensors and vectors are 1st-order tensors, matrices are 2nd-order tensors. We denote matrices by bold capital letters (e.g., 𝐗, 𝐘, and 𝐙), and represent them in code by tensors with two axes. The expression 𝐀∈ℝm×n indicates that a matrix 𝐀 contains m×n real-valued scalars, arranged as m rows and n columns. When m=n, 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., aij is the value that belongs to 𝐀’s ith row and jth column:
英語のヒント
スカラーが0th階のテンソルで、ベクトルが1st階のテンソルであるのと同じように、行列は2nd階のテンソルである。行列は太字の大文字(たとえば𝐗、𝐘、𝐙)で表し、コードでは軸が二つのテンソルで表す。式𝐀∈ℝm×nは、行列𝐀が、m行n列に並んだm×n個の実数値のスカラーを含むことを示す。m=nのとき、その行列は正方行列であるという。見た目のうえでは、どんな行列も表として描ける。個々の要素を指すには、行と列の両方のインデックスを添え字に付ける。たとえばaijは、𝐀のith行jth列に属する値である。
𝐀=[a11a12⋯a1na21a22⋯a2n⋮⋮⋱⋮am1am2⋯amn].(2.3.2)
In code, we represent a matrix 𝐀∈ℝm×n by a 2nd-order tensor with shape (m, n). We can convert any appropriately sized m×n tensor into an m×n matrix by passing the desired shape to reshape:
英語のヒント
コードでは、行列𝐀∈ℝm×nを、形状が(m, n)の2nd階のテンソルで表す。reshapeに望む形状を渡せば、適切な大きさのm×nのテンソルをm×nの行列に変換できる。
A = torch.arange(6).reshape(3, 2)
A
tensor([[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 bij=aji for all i and j. Thus, the transpose of an m×n matrix is an n×m matrix:
英語のヒント
軸を入れ替えたいこともある。行列の行と列を入れ替えた結果を、その転置という。形式的には、行列𝐀の転置を𝐀⊤で表し、𝐁=𝐀⊤なら、すべてのiとjについてbij=ajiである。したがって、m×nの行列の転置はn×mの行列である。
𝐀⊤=[a11a21…am1a12a22…am2⋮⋮⋱⋮a1na2n…amn].(2.3.3)
In code, we can access any matrix’s transpose as follows:
英語のヒント
コードでは、どんな行列の転置も次のように得られる。
A.T
tensor([[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.T
tensor([[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.
英語のヒント
行列はデータセットを表すのに便利である。普通、行は個々のレコードに、列は異なる属性に対応する。