第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 -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 , also known as zero-based indexing, whereas in linear algebra subscripts begin at (one-based indexing).
英語のヒント
ベクトルは階のテンソルとして実装される。一般に、こうしたテンソルは、メモリの制約の範囲で任意の長さをとれる。注意:Pythonでは、ほとんどのプログラミング言語と同じく、ベクトルのインデックスはから始まる(ゼロ始まりのインデックスとも呼ばれる)。これに対して線形代数では、添え字はから始まる(1始まりのインデックス)。
x = torch.arange(3)
xtensor([0, 1, 2])We can refer to an element of a vector by using a subscript. For example, denotes the second element of . Since is a scalar, we do not bold it. By default, we visualize vectors by stacking their elements vertically.
英語のヒント
ベクトルの要素は添え字を使って指せる。たとえば、はの2番目の要素を表す。はスカラーなので、太字にはしない。既定では、ベクトルは要素を縦に積み重ねて表示する。
(2.3.1)
Here 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.
英語のヒント
ここではベクトルの要素である。後で、こうした列ベクトルと、要素を横に並べた行ベクトルとを区別する。テンソルの要素にはインデックス指定でアクセスすることを思い出そう。
x[2]tensor(2)To indicate that a vector contains elements, we write . Formally, we call the dimensionality of the vector. In code, this corresponds to the tensor’s length, accessible via Python’s built-in
len function.英語のヒント
ベクトルが個の要素をもつことを示すには、と書く。形式的には、をベクトルの次元数と呼ぶ。コードでは、これはテンソルの長さに対応し、Pythonの組み込み関数
lenで得られる。len(x)3We 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.shapetorch.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.
英語のヒント
「次元」という言葉は、軸の数と、ある軸に沿った長さの両方の意味に使い回されることがよくある。この混乱を避けるため、軸の数を指すには「階数」を、成分の数を指すにはもっぱら「次元数」を使う。