# 向量内积

在数学中，点积（Dot Product）又称数量积，是一个接受两个等长度的数字序列（通常是向量坐标），然后返回单个数字的代数运算。在欧几里德几何中，两个笛卡尔坐标向量的点积常称为内积（Inner Product）。

从代数的角度看，先对两个数字序列中的每组对应元素求积，再对所有积求和，结果即为点积。

从几何角度看，点积则是两个向量的长度与它们的夹角的余弦的积。

**代数定义：**

两个向量 $$\vec{a}=\[a\_1, a\_2, ..., a\_n]$$ 和 $$\vec{b}=\[b\_1, b\_2, ..., b\_n]$$ 的点积定义为：

$$
\vec{a} \cdot \vec{b} = \displaystyle\sum\_{i=1}^n a\_ib\_i= a\_1b\_1+a\_2b\_2+...+ a\_nb\_n
$$

**几何定义：**

在欧几里德空间中，点积可以直观的定义为：

$$
\vec{a} \cdot \vec{b} =|{a}||{b} | \mathrm{cos}\theta
$$

这里$$|\vec{x}|$$表示向量$$\vec{x}$$的模的长度，$$\theta$$表示两个向量的角度。

当两个向量互相垂直时点积总是为零。因为$$\mathrm{cos} 90 = 0$$。当两个向量方向相同时，角度为$$0$$，内积为正的最大；当两个向量方向相反时，角度为$$180$$，内积为负的最大。

![](/files/-LJhagyXrYMHc96sW7qH)

若$${a}$$和$${b}$$都是单位向量（长度为1），它们的点积就是它们的夹角的余弦。那么给定两个向量，它们之间的夹角可以通过下列公式得到：

$$
\mathrm{cos} \theta =\frac{ \vec{a} \cdot \vec{b} }{ |{a}| |{b}|}
$$

![](/files/-LJhagyZR0mIRuGf_chN)

向量的内积可以理解为向量A在向量B上的投影跟向量B的长度的乘积。

> source: <https://zh.wikipedia.org/wiki/点积>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://zhjunqin.gitbook.io/machine-learning/ji-qi-xue-xi/shu-xue-ji-chu/wei-ji-fen/xiang-liang-nei-ji.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
