Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm taking Andrew Ng's course on Machine Learning through Coursera. For equations, superscripts are used instead of subscripts. For example, in the following equation $x^{(i)}$ is used instead of $x_i$:

$J(\theta_0, \theta_1) = \frac{1}{2m} \sum\limits_{i=1}^{m}{(h_\theta(x^{(i)}) - y^{(i)})^2}$

Apparently, this is common practice. My question is why use superscripts instead of subscripts? Superscripts are already used for exponentiation. Granted I seem to be able to disambiguate between the superscript and exponentiation use cases by paying attention to whether or not parentheses are present, but it still seems confusing.

share|improve this question
I suspect it's perhaps because some computer science people are not versed in standard mathematical notation, and therefore make up their own notation. Actuaries do this sometimes too, and it's frustrating when you get to more complicated concepts. – rocinante Feb 3 at 21:36
Is i indexing over the data set size, or over the elements of the vector x? If the former, that's totally standard. If the latter, that's totally non-standard. And the reason why the superscript is used is because sometimes you want to refer to the element of the vector using the subscript. – Rex Kerr Feb 4 at 0:06
@rocinante lol no, it's because subscripts are already taken for indexing vectors. – Neil G Feb 4 at 4:48
@rocinante That's rather presumptuous. What about contravariant vectors/Einstein notation? – Will Vousden Feb 4 at 10:21
@rocinante I have to echo others in underlining that your wording is unfortunate. We all have a tendency to regard what is local and familiar as standard. – Nick Cox Feb 4 at 19:08
up vote 24 down vote accepted

If $x$ denotes a vector $x \in \mathbb R^m$ then $x_i$ is a standard notation for the $i$-th coordinate of $x$, i.e. $$x = (x_1, x_2, \ldots, x_m)\in\mathbb R^m.$$

If you have a collection of $n$ such vectors, how would you denote an $i$-th vector? You cannot write $x_i$, this has other standard meaning. So sometimes people write $x^{(i)}$ and that is I believe why Andrew Ng does it.


\begin{equation} x^{(1)} = (x_1^{(1)}, x_2^{(1)}, \ldots, x_m^{(1)}) \in \mathbb R^m\\ x^{(2)} = (x_1^{(2)}, x_2^{(2)}, \ldots, x_m^{(2)}) \in \mathbb R^m\\ \ldots \\ x^{(n)} = (x_1^{(n)}, x_2^{(n)}, \ldots, x_m^{(n)}) \in \mathbb R^m.\\ \end{equation}

share|improve this answer
I'm not disagreeing, but often $x_{ij}$ is used, ie for repeated measurements. – Cliff AB Feb 4 at 0:13
Yes, but $x_{ij}$ is equivalent to my $x^{(i)}_j$; what would be the equivalent of $x^{(i)}$? – amoeba Feb 4 at 0:14
yes, that's an advantage. I think $x_{i.}$ is used sometimes, but this could be confused with $\sum_{j= 1}^n x_{ij}/m$. – Cliff AB Feb 4 at 0:16
If you wish to iterate over matrices then the $x_{mn}^{(i)}$ seems the most intuitive way to do so. Therefore the notation stays consistent when moving from vectors to matrices. – josh Feb 4 at 10:04
@JAB Yes, it's to make the notation more explicit ("type hinting" as you say). Of course one can agree to use $x_i$ for the $i$-th vector and $x_{ij}$ for the $j$-th element of the $i$-th vector. There are various conventions possible, this is just one of them. I am not even saying it is the best one, just explaining the rationale behind it. – amoeba Feb 4 at 14:44

The use of super scripts as you have stated I believe is not very common in machine learning literature. I'd have to review Ng's course notes to confirm, but if he's putting that use there, I would say he would be origin of the proliferation of this notation. This is a possibility. Either way, not to be too unkind, but I don't think many of the online course students are publishing literature on machine learning, so this notation is not very common in the actual literature. After all, these are introductory courses in machine learning, not PhD level courses.

What is very common with super scripts is to denote the iteration of an algorithm using super scripts. For example, you could write an iteration of Newton's method as

$ \theta^{(t+1)} = \theta^{(t)} - H(\theta^{(t)}) ^{-1} \nabla \theta^{(t)}$

where $ H(\theta^{(t)}) $ is the Hessian and $\nabla \theta^{(t)}$ is the gradient.

(...yes this is not quite the best way to implement Newton's method due to the inversion of the Hessian matrix...)

Here, $\theta^{(t)}$ represents the value of $\theta$ in the $t^{th}$ iteration. This is the most common (but certainly not only) use of super scripts that I am aware of.

EDIT: To clarify, in the original question, it appeared to suggest that in the ML notation, $x^{(i)}$ was equivalent to statistic's $x_i$ notation. In my answer, I state that this is not truly prevalent in ML literature. This is true. However, as pointed out by @amoeba, there is plenty of superscript notation in ML literature for data, but in these cases $x^{(i)}$ does not typically mean the $i^{th}$ observation of a single vector $x$.

share|improve this answer
The clash with the use of parenthesized/bracketed superscripts for iteration counts (a notation that is in common use across a wide range of areas) is a really important thing to raise. – Glen_b Feb 3 at 22:02
It is also commonly used to indicate the index of the sample in the training set, which is like the iteration but not exactly the same because you usually end up iterating through your training set many times. – Rex Kerr Feb 4 at 0:07
I've also seen iteration counts noted using subscripts ($a_{n+1} = a_n + 1$) as well as in line ($a(n+1) = a(n) + 1$). Which is why, when using some specific notation, I'll usually put something at the start to disambiguate (e.g. saying "in the following series, blah blah blah" and then putting the math). Thus, whatever notation is in use, readers can (hopefully) intuit the meaning for potentially ambiguous cases rather than having to guess based on the conventions they know. – JAB Feb 4 at 14:00
I agree with @JAB. More generally, I don't think it's heinous for people who will be writing and using code to borrow notation from software in mathematical treatments. For example, and contentiously, computing people are way ahead of many mathematical groups in using clean notation such as $(x > 0)$, to be evaluated as 1 if true and 0 if false, instead of unnecessary formalisms such as $I(x > 0)$; here I am merely following behind Donald Knuth. – Nick Cox Feb 4 at 19:04
@NickCox I generally only see the $I(x > 0)$ form when it comes to probability; otherwise, $x > 0$ is just an inequality constraint. When it comes to mathematical equations, they're either broken up into piecewise representations or they just represent the equation itself as an inequality as doing otherwise would induce ambiguity. (It's similar to how $=$ in math is more subtle than either = or == in most programming languages; it introduces a constraint or definition rather than an actual assignment or equality check.) – JAB Feb 4 at 20:58

Superscripts are already used for exponentiation.

In mathematics superscripts are used left and right depending on the field. The choice is always historical legacy, nothing more. Whoever first got into the field set the convention of using sub- or superscripts.

Two examples. Superscripts are used to denote derivatives: $f(x)^{(n)}$

In tensor algebra both super and subscripts are used heavily for the same thing like $R^i_i$ could mean $i$ rows and $j$ columns. It's quite expressive: $T_i^k=R_i^jC_j^k$

Also I remember using scripts before letters (prescripts) in Physics, e.g. $^i_jB_k^l$. I think it was with tensors.

Hence, the choice of superscripts by Ng is purely historical too. There's no real reason to use or not use them, or prefer them to subscripts. Actually, I believe that here ML people are using tensor notation. They definitely are well versed in the subject, e.g. see this paper.

share|improve this answer
Another example for your point: Einstein notation – Neil G Feb 4 at 19:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.