Why could this formula "dist(x, y) = sqrt(dot(x, x) - 2 * dot(x, y) + dot(y, y))" compute the euclidean distance of two matrices? sklearn's doc gives this formula for sklearn.metrics.pairwise.euclidean_distances

dist(x, y) = sqrt(dot(x, x) - 2 * dot(x, y) + dot(y, y))

to compute the euclidean distance between of 2 matrices.
Is this formula derived from the euclidean distance of two vectors?
${\displaystyle {\begin{aligned}d(\mathbf {p} ,\mathbf {q} )=d(\mathbf {q} ,\mathbf {p} )&={\sqrt {(q_{1}-p_{1})^{2}+(q_{2}-p_{2})^{2}+\cdots +(q_{n}-p_{n})^{2}}}\\[8pt]&={\sqrt {\sum _{i=1}^{n}(q_{i}-p_{i})^{2}}}.\end{aligned}}}$
Can someone elaborate the deduction?
 A: I'll write $\langle x,y\rangle = \sum_{i=1}^n x_iy_i$ to mean the standard inner (dot) product between two vectors in $\Bbb{R}^n$. Then, as you mentioned, the Euclidean distance is given by
\begin{align}
\text{dist}(x,y) &= \sqrt{\sum_{i=1}^n (x_i-y_i)^2 } \\
&= \sqrt{\langle x-y,x-y\rangle} \tag{$*$}
\end{align}
Now, you need to know that $\langle \cdot, \cdot \rangle$ is bilinear and symmetric (i.e $\langle x,y \rangle = \langle y,x \rangle$), which means the usual algebra of "expanding everything" term by term works. So,
\begin{align}
\langle x-y, x-y\rangle &= \langle x, x-y\rangle - \langle y, x-y\rangle \\
&= \big( \langle x,x \rangle - \langle x, y\rangle\big) - \big( \langle y, x \rangle - \langle y,y \rangle\big) \\
&= \langle x,x\rangle - 2 \langle x,y \rangle + \langle y,y \rangle \tag{$**$}
\end{align}
Therefore, substituting $(**)$ into $(*)$ yields
\begin{align}
\text{dist}(x,y) &= \sqrt{\langle x,x\rangle - 2 \langle x,y \rangle + \langle y,y \rangle}
\end{align}
A: Because it is just:
$$\sqrt{\operatorname{dot}(\mathbf{x} - \mathbf{y}, \mathbf{x}- \mathbf{y})} = \lvert \mathbf{x} - \mathbf{y} \rvert$$
(Expand the expression under the square root)
