Given $g:R^n \rightarrow R^k$ and $h:R^k \rightarrow R$, we have $f(x) = h(g(x))$.
Using the chain rule, we can differentiate $f(x)$ to get
$f'(x) = \nabla^Th(g(x))g'(x)$
My question is why do we take the transpose of the gradient of $h$? Is it just to make sure the result is a scalar, since $f(x)$ is in $R$?
If so, does it mean that every time we do vector differentiation, we need to ensure the output matches the size of the result, and take transpose if necessary (i.e. no hard and fast rule of taking transpose)?