TITLE: The gradient as a row versus column vector
QUESTION [25 upvotes]: Kaplan's Advanced Calculus defines the gradient of a function $f : \mathbb{R^n} \to \mathbb{R}$ as the $1 \times n$ row vector whose entries respectively contain the $n$ partial derivatives
of $f$. By this definition then, the gradient is just the Jacobian matrix of the transformation.
We also know that using the Riesz representation theorem, assuming $f$ is differentiable at the point $x$, we can define the gradient as the unique vector $\nabla f$ such that
$$ df(x)(h) = \langle h, \nabla f(x) \rangle, \quad h \in \mathbb{R}^n $$
Assuming we ignore the distinction between row vectors and column vectors, the former definition
follows easily from the latter. But, row vectors and column vectors are not the same things. So,
I have the following questions:

Is the distinction here between row/column vectors important?
If (1) is true, then how can we know from the second defintion that the vector
in question is a row vector and not a column vector?

REPLY [4 votes]: Here's a simple heuristic. TL;DR: If the domain of $f: R^n\to R$ is a space of column vectors, then $f'(x)$ needs to be a row vector for the linear approximation property to make sense.
To make the distinction between row and column vectors explicit, I'll write $R^{k\times 1}$ and $R^{1\times k}$ for the spaces of $k$-dimensional column and row vectors of real numbers, respectively.
If $f:R^{n\times 1}\to R^{m\times 1}$, then, for every $x\in R^{n\times 1}$, the derivative $f'(x)$ is characterized by its linear approximation property,
$$
f(x + h) \approx f(x) + f'(x)h,
$$
for small $h\in R^{n\times 1}$.
Now think about the sizes of the matrices involved: $f(x)$ has size $m\times 1$, so $f'(x)h$ also needs to have size $m\times 1$ for the right hand side to make sense.
But $h\in R^{n\times 1}$, so $f'(x)h$ has size $m\times 1$ exactly when $f'(x)$ has size $m\times n$.
In particular, if $f:R^{n\times 1}\to R$, then $f'(x)$ needs to be an $1\times m$ matrix, i.e., a row vector.