プリンキピア

第2章準備

2.3.2. Vectors2.3.2 ベクトル

For current purposes, you can think of a vector as a fixed-length array of scalars. As with their code counterparts, we call these scalars the elements of the vector (synonyms include entries and components). When vectors represent examples from real-world datasets, their values hold some real-world significance. For example, if we were training a model to predict the risk of a loan defaulting, we might associate each applicant with a vector whose components correspond to quantities like their income, length of employment, or number of previous defaults. If we were studying the risk of heart attack, each vector might represent a patient and its components might correspond to their most recent vital signs, cholesterol levels, minutes of exercise per day, etc. We denote vectors by bold lowercase letters, (e.g., 𝐱, 𝐲, and 𝐳).
英語のヒント
今のところは、ベクトルをスカラーの固定長の配列と考えてよい。コードでの対応物と同じように、これらのスカラーをベクトルの要素と呼ぶ(同義語に成分がある)。ベクトルが現実のデータセットの事例を表すとき、その値は現実世界での意味をもつ。たとえば、ローンの債務不履行の危険を予測するモデルを訓練するなら、各申込者を、収入、勤続年数、過去の不履行の回数といった量に成分が対応するベクトルに結びつけるかもしれない。心臓発作の危険を研究するなら、各ベクトルが一人の患者を表し、その成分が直近のバイタルサイン、コレステロール値、1日あたりの運動時間などに対応するかもしれない。ベクトルは太字の小文字(たとえば𝐱、𝐲、𝐳)で表す。
Vectors are implemented as 1st-order tensors. In general, such tensors can have arbitrary lengths, subject to memory limitations. Caution: in Python, as in most programming languages, vector indices start at 0, also known as zero-based indexing, whereas in linear algebra subscripts begin at 1 (one-based indexing).
英語のヒント
ベクトルは1st階のテンソルとして実装される。一般に、こうしたテンソルは、メモリの制約の範囲で任意の長さをとれる。注意:Pythonでは、ほとんどのプログラミング言語と同じく、ベクトルのインデックスは0から始まる(ゼロ始まりのインデックスとも呼ばれる)。これに対して線形代数では、添え字は1から始まる(1始まりのインデックス)。
x = torch.arange(3)
x
tensor([0, 1, 2])
We can refer to an element of a vector by using a subscript. For example, x2 denotes the second element of 𝐱. Since x2 is a scalar, we do not bold it. By default, we visualize vectors by stacking their elements vertically.
英語のヒント
ベクトルの要素は添え字を使って指せる。たとえば、x2は𝐱の2番目の要素を表す。x2はスカラーなので、太字にはしない。既定では、ベクトルは要素を縦に積み重ねて表示する。
𝐱=[x1⋮xn],(2.3.1)
Here x1,…,xn are elements of the vector. Later on, we will distinguish between such column vectors and row vectors whose elements are stacked horizontally. Recall that we access a tensor’s elements via indexing.
英語のヒント
ここでx1,…,xnはベクトルの要素である。後で、こうした列ベクトルと、要素を横に並べた行ベクトルとを区別する。テンソルの要素にはインデックス指定でアクセスすることを思い出そう。
x[2]
tensor(2)
To indicate that a vector contains n elements, we write 𝐱∈ℝn. Formally, we call n the dimensionality of the vector. In code, this corresponds to the tensor’s length, accessible via Python’s built-in len function.
英語のヒント
ベクトルがn個の要素をもつことを示すには、𝐱∈ℝnと書く。形式的には、nをベクトルの次元数と呼ぶ。コードでは、これはテンソルの長さに対応し、Pythonの組み込み関数lenで得られる。
len(x)
3
We can also access the length via the shape attribute. The shape is a tuple that indicates a tensor’s length along each axis. Tensors with just one axis have shapes with just one element.
英語のヒント
長さはshape属性でも得られる。形状は、各軸に沿ったテンソルの長さを示すタプルである。軸が一つだけのテンソルは、要素が一つだけの形状をもつ。
x.shape
torch.Size([3])
Oftentimes, the word “dimension” gets overloaded to mean both the number of axes and the length along a particular axis. To avoid this confusion, we use order to refer to the number of axes and dimensionality exclusively to refer to the number of components.
英語のヒント
「次元」という言葉は、軸の数と、ある軸に沿った長さの両方の意味に使い回されることがよくある。この混乱を避けるため、軸の数を指すには「階数」を、成分の数を指すにはもっぱら「次元数」を使う。