基礎編

情報数理に関する基本的な計算問題

ベクトル内積の計算 レベル1

ニューラルネットワークの入力ベクトル \( \mathbf{x} = [2, -1, 3] \) と重みベクトル \( \mathbf{w} = [0.5, 1, -0.2] \) があります。これらのベクトルの内積 \( \mathbf{w} \cdot \mathbf{x} \) を計算しなさい。

解説
解答と解説を表示
<h4>ベクトル内積の計算</h4> <p>2つのベクトル \( \mathbf{w} = [w_1, w_2, ..., w_n] \) と \( \mathbf{x} = [x_1, x_2, ..., x_n] \) の内積は、対応する要素同士の積の合計として定義されます。</p> <div class="formula"> $ \mathbf{w} \cdot \mathbf{x} = w_1 x_1 + w_2 x_2 + ... + w_n x_n = \sum_{i=1}^{n} w_i x_i$ </div><p>与えられたベクトルは \( \mathbf{x} = [2, -1, 3] \) と \( \mathbf{w} = [0.5, 1, -0.2] \) です。</p><p>内積を計算します:</p> <div class="formula"> $\mathbf{w} \cdot \mathbf{x} = (0.5 \times 2) + (1 \times (-1)) + ((-0.2) \times 3) = 1 + (-1) + (-0.6) = 1 - 1 - 0.6 = -0.6$ </div><p>したがって、ベクトルの内積は -0.6 です。</p><div class="key-point"> <div class="key-point-title">ニューラルネットワークにおける内積</div> <p>ニューラルネットワークにおいて、ニューロンの入力に対する重み付き和は、まさにこの内積計算によって求められます。入力ベクトルと重みベクトルの内積にバイアス項を加えたものが、活性化関数への入力となります。</p> <div class="formula"> $\text{活性化関数への入力} = (\mathbf{w} \cdot \mathbf{x}) + b = \sum_{i=1}^{n} w_i x_i + b$ </div> <p>ここで \(b\) はバイアス項です。</p> </div><h5>NumPyによる計算</h5> <p>PythonのライブラリNumPyを使うと、ベクトル演算を簡単に行えます。</p> <div class="code-block"> <pre> import numpy as npx = np.array([2, -1, 3]) w = np.array([0.5, 1, -0.2])# 内積の計算 dot_product = np.dot(w, x) # または # dot_product = w @ xprint(f"Vector x: {x}") print(f"Vector w: {w}") print(f"Dot product (w . x): {dot_product}") # 出力: # Vector x: [2 -1 3] # Vector w: [0.5 1. -0.2] # Dot product (w . x): -0.6 </pre> </div>
問題 1/1
カテゴリ一覧に戻る