Does this formula $\cos\theta=\frac{(u|v)}{|u||v|}$ work for a general inner product? I know the following formula only works for the vector space $\mathbb R^n$, and not necessarily for other vector spaces. I would like to know if this formula works for every real inner product on $\mathbb R^n$.

$$\cos\theta=\frac{(u|v)}{|u||v|}$$

 A: Edit
Does this formula work for every real inner product on $\mathbb{R}$? No, it does not. In fact, it only works for positive scalar multiples of the standard inner product.
To see why, let $(\cdot, \cdot)'$ be any real inner product on $\mathbb{R}^n$ that obeys the formula $\cos \theta = \frac{(u,v)'}{\|u\|'\|v\|'}$ for all nonzero vectors $u, v \in \mathbb{R}^n$, where $\|u\|'$ is short for $\sqrt{(u,u)'}$. Then $\cos \theta$ is also equal to $\frac{(u,v)}{\|u\|\|v\|}$ where that is the standard inner product and norm. So we have, for all $u, v \ne 0$ that
$$
\frac{(u,v)'}{\sqrt{(u,u)'(v,v)'}}
= \frac{(u,v)}{\sqrt{(u,u)(v,v)}}
$$
Let $e_1, \ldots, e_n$ be the standard basis.
For $i \ne j$, taking $u = e_i, v = e_j$ in the above, the RHS becomes zero. Thus we must have $(e_i, e_j)' = 0$.
Next, taking $u = \alpha e_i + \beta e_j$, $v = \gamma e_i + \delta e_j$, using properties of an inner product and the fact we already proved that $(e_i, e_j)' = 0$, we get
$$
\frac{\alpha \gamma(e_i,e_i)' + \beta \delta(e_j,e_j)'}{\sqrt{(\alpha^2(e_i,e_i)' + \beta^2(e_j,e_j)')(\gamma^2(e_i,e_i)' + \delta^2(e_j,e_j)')}} = 
\frac{\alpha \gamma + \beta \delta}{\sqrt{(\alpha^2 + \beta^2)(\gamma^2 + \delta^2)}}
$$
Writing $k = \frac{(e_i,e_i)'}{(e_j,e_j)'} > 0$, we get
$$
\frac{\alpha \gamma k + \beta \delta}{\sqrt{(\alpha^2 k + \beta^2)(\gamma^2 k+ \delta^2)}} = 
\frac{\alpha \gamma + \beta \delta}{\sqrt{(\alpha^2 + \beta^2)(\gamma^2 + \delta^2)}}
$$
for all $\alpha, \beta, \delta, \gamma \in \mathbb{R}$
where $\alpha, \beta$ are not both zero and $\delta, \gamma$ are not both zero.
Next we can plug in $\beta = 0$ to find that
$$
\frac{\gamma k}{\sqrt{k(\gamma^2 k + \delta^2)}}
= \frac{\gamma}{\sqrt{\gamma^2 + \delta^2}}
$$
Squaring and rearranging, and assuming $\gamma, \delta \ne 0$
$$
k = \frac{\gamma^2 k + \delta^2}{\gamma^2 + \delta^2}
\implies \delta^2 k = \delta^2 \implies k = 1.
$$
It follows that $(e_i,e_i)' = (e_j,e_j)'$. And this was true for any $i, j$.
Therefore for some positive constant $c$, $(e_i,e_i)' = c (e_i,e_i)$ for all $i$, and $(e_i,e_j)' = c(e_i,e_j) = 0$ for all $i \ne j$.
As an inner product is determined by its values on the standard basis, we have shown that $(\cdot, \cdot)'$ must be just a positive scaling of the standard inner product.

I include the original answer below, which misunderstood the question.
Original answer
Yes, the formula works for all $u, v \in \mathbb{R}^n$ -- with an important exception if $u$ or $v$ is the zero vector $\vec{0}$, when there is no well-defined angle.
In fact, this is sometimes taken as the definition of the angle between two vectors. Specifically, we say that the angle between two vectors, $\theta$, is equal to $\arccos$ of your expression, i.e. it's the unique angle between $0$ and $\pi$ which satisfies that equation.
The reason we may use this as a definition is that trying to nail down exactly what the "angle between two vectors" in $\mathbb{R}^n$ is a little complicated. Geometrically it's clear when $n \le 3$; when $n \ge 4$ not so much -- and anyway, how do we translate our geometrical idea of an angle into an algebraic definition? So we can just note that the dot product does the job of what we want, and use that as the definition.
A: If we have a general inner product space then the expression $$\frac{\left<u,v\right>}{\|u\|\|v\|} \equiv \cos\theta$$ is usually the definition of "an angle" between the two vectors $u$ and $v$. However only when the inner product is the usual dot-product and the vector space is $\mathbb{R}^n$ does this angle have the usual geometrical interpretation. We know from Cauchy-Schwarz that we always have $$\frac{\left<u,v\right>}{\|u\|\|v\|}\in[-1,1]$$ so it does makes sense to associate this quantity with the cosine of "an angle" in other cases also. We further have that this angle satisfy $\theta = 0^\circ$ or $\theta = 180^\circ$ if and only if $u$ and $v$ are lineary dependent. Thus one interpretation of $\theta$ is as a measure of how close $u$ and $v$ are to being lineary dependent (a generalized notion of the concept of two vectors being parallel).
It turns out to be quite useful to introduce notions like "angle" and "parallel" when working with more general inner product spaces as it allows us to use some of our old geometrical intuition even though the vectors might be very different from the 'standard' vectors.
