Alterna · learning material

01.4 Which gives you the sum of the works

Multiply the corresponding coordinates of the two vectors and folding, and get one number related to the length and direction of the arrows.

What this material covers

Content and key concepts

On the previous page, how to measure length.
Multiply the corresponding coordinates of the two vectors and folding, and get one number related to the length and direction of the arrows.
Two vectors: [3.4] and [2.0].
Координаты и расчёт геометрического примера приведены в тексте. Для изменения пространственного рисунка включитеJavaScript.
One scalar is derived from the component
The scalar work of two vectors of the same dimension is defined as
x
T
y
=
∑
i
=
1
n
x
i
y
i
.
x^Ty=\sum_{i=1}^{n}x_i y_i.
x
T
y
=
i
=
1
∑
n
​
x
i
​
y
i
​
.
The operation performs two actions: multiplys the components, then summarizes all the results.
x
=
[
1
,
2
]
T
x=[1,2]^T
x
=
[
1
,
2
]
T
,
y
=
[
3
,
4
]
T
y=[3,4]^T
y
=
[
3
,
4
]
T
intermediate vector of works equals
[
3
,
8
]
T
[3,8]^T
[
3
,
8
]
T
The component result is called Adamar's product and should not replace the scalar result.
Shape helps detect a mistake:
[n] · [n]
Gives a scalar, while
[n] * [n]
in many libraries
[n]
. NumPy shows this distinction as
x @ y
v.
x * y
.
Arifmetics encodes the Euclid angle
For non-zero vectors, the euclido scalar is connected to the angle.
θ
\theta
θ
:
x
T
y
=
∥
x
∥
2
∥
y
∥
2
cos
⁡
θ
.
x^Ty=\|x\|_2\|y\|_2\cos\theta.
x
T
y
=
∥
x
∥
2
​
∥
y
∥
2
​
cos
θ
.
Prix
x
=
[
3
,
4
]
T
x=[3,4]^T
x
=
[
3
,
4
]
T
,
y
=
[
1
,
0
]
T
y=[1,0]^T
y
=
[
1
,
0
]
T
dot equals
3
3
3
, a
∥
x
∥
2
∥
y
∥
2
=
5
\|x\|_2\|y\|_2=5
∥
x
∥
2
​
∥
y
∥
2
​
=
5
, so
cos
⁡
θ
=
3
/
5
\cos\theta=3/5
cos
θ
=
3/5
" . If replaced
y
y
y
as at
[
0
,
1
]
T
[0,1]^T
[
0
,
1
]
T
dot becomes 4: vertical axis aligned with
x
x
x
Harder horizontal.
The sign gives quality information:
x
T
y
>
0
x^Ty>0
x
T
y
>
0
: angle of sharp
x
T
y
=
0
x^Ty=0
x
T
y
=
0
:: Orthogonal vectors or one of them is zero;
x
T
y
<
0
x^Ty<0
x
T
y
<
0
: angle is dumb.
Dot = 0 per se does not allow for coal if a zero vector is present: the arithmetic sum is determined but the direction of the zero vector does not exist.
Compensation for deposits creates orthogonality
Here we go.
y
=
[
−
4
,
3
]
T
y=[-4,3]^T
y
=
[
−
4
,
3
]
T
Then.
x
T
y
=
3
(
−
4
)
+
4
(
3
)
=
−
12
+
12
=
0.
x^Ty=3(-4)+4(3)=-12+12=0.
x
T
y
=
3
(
−
4
)
+
4
(
3
)
=
−
12
+
12
=
0.
Orthogonality did not arise because every piece is equal to zero, but because negative and positive deposits were accurately compensated.
[
−
4
,
3
]
T
[-4,3]^T
[
−
4
,
3
]
T
is a turn
[
3
,
4
]
T
[3,4]^T
[
3
,
4
]
T
It is 90 degrees and has the same length of 5.
Dot measures both direction and scale
If
y
=
x
y=x
y
=
x
, that's
x
T
y
=
∥
x
∥
2
2
=
25
x^Ty=\|x\|_2^2=25
x
T
y
=
∥
x
∥
2
2
​
=
25
If
y
=
2
x
y=2x
y
=
2
x
if the angle is zero, but the dot doubles to 50.
y
=
−
x
y=-x
y
=
−
x
the length of the former, and the dot is equal to
−
25
-25
−
25
Therefore, a large positive score may be the result of long, strong overlap of direction or both.
This is essential for attention: score query-key up to the norm depends on the scale of the submissions.
d
\sqrt d
d
​
in a scaled dot-produce output control the scale of typical logs, but does not turn every dot into cosine.
Inequality of Koshi-Bunyakovsky
∣
x
T
y
∣
≤
∥
x
∥
2
∥
y
∥
2
|x^Ty|\le\|x\|_2\|y\|_2
∣
x
T
y
∣
≤
∥
x
∥
2
​
∥
y
∥
2
​
Ensures that the normal attitude lies in
[
−
1
,
1
]
[-1,1]
[
−
1
,
1
]
Equality is achieved for linearly dependent vectors: a sign plus one direction and minus the opposite.
1
+
ε
1+\varepsilon
1
+
ε
due to rounding; before
arccos
It is permissible to limit it to a range
[
−
1
,
1
]
[-1,1]
[
−
1
,
1
]
This restriction only corrects the numerical noise, but not the incompatible shapes and the wrong formula.
Calculation of dot length
n
n
n
Demands
n
n
n
multipliers and
n
−
1
n-1
n
−
1
The sum is calculated for multiple pairs of query-key. The bottom lab shows both intermediate works and the sum: see which deposits reinforce each other and which ones are compensated.
x, y = [1, 2], [3, 4]
products = [a*b for a, b in zip(x, y)]
dot = sum(products)
assert products == [3, 8] and dot == 11
The code repeats the operations just taken care of.
Completely checked Python-example Chapter
Available with a separate file; the short piece shown does not replace its implementation.
Two sets of numbers gave one estimate; it depends on both direction and length; it's not yet normal.
The closest point in the direction, how does this question go on?
Python examples of Chapter 01
Academic base

Textbook contents map