Skip to content
Glacius
CalculusConcept reference

Jacobians

The Jacobian has entry (i,j) equal to the partial derivative of output i with respect to input j.

On this page 10 sections
  1. Overview
  2. Organize several outputs and inputs
  3. Build the matrix one output at a time
  4. Keep the output and input counts separate
  5. Evaluate the derivative at a point
  6. Use the Jacobian as a local linear map
  7. Key takeaway
  8. Further questions
  9. Sources & further reading
  10. Concept connections

01Organize several outputs and inputs#

A gradient collects coordinate rates for one scalar output. A vector-valued function has several output coordinates, each with its own dependence on the inputs. Its Jacobian puts all those first derivatives in a matrix.

We use one row per output and one column per input. If there are nn inputs and mm outputs, the Jacobian has shape m×nm\times n.

Write FiF_i for output ii, and xjx_j for input jj. The entry in row ii, column jj is

(JF)ij=∂Fi∂xj.(J_F)_{ij}=\frac{\partial F_i}{\partial x_j}.

Read JFJ_F as “the Jacobian of FF.” The subscript names the function. Writing JF(p)J_F(p) means evaluate all its entries at the input point pp.

02Build the matrix one output at a time#

Consider F(x,y)=(x2+y, xy)F(x,y)=(x^2+y,\ xy). Its first output is F1=x2+yF_1=x^2+y. Differentiating that output with respect to xx gives 2x2x; differentiating it with respect to yy gives 11.

The first row is therefore (2x,1)(2x,1). Both entries describe the same output, under two different input changes.

The second output is F2=xyF_2=xy. Its xx-partial is yy, because yy stays fixed. Its yy-partial is xx, because xx stays fixed. This gives the second row (y,x)(y,x).

JF(x,y)=(2x1yx).J_F(x,y)=\begin{pmatrix}2x&1\\y&x\end{pmatrix}.

Read down a column to see how one input affects every output. Read across a row to see how every input affects one output.

For F(x,y)=(x squared+y,xy), rows correspond to outputs F1 and F2 and columns to inputs x and y. The first row is (2x,1), and the second is (y,x). The labeled array is the full two-by-two Jacobian.For F(x,y)=(x squared+y,xy), rows correspond to outputs F1 and F2 and columns to inputs x and y. The first row is (2x,1), and the second is (y,x). The labeled array is the full two-by-two Jacobian.
Figure 1For F(x,y)=(x squared+y,xy), rows correspond to outputs F1 and F2 and columns to inputs x and y. The first row is (2x,1), and the second is (y,x). The labeled array is the full two-by-two Jacobian.
Link to this figure ↗Download SVGDownload PNG

For a single scalar output, this convention produces a one-row Jacobian. Our gradient convention uses a column, so for a differentiable scalar function the Jacobian is the transpose of its gradient.

Neither convention changes any partial derivative. It changes how we arrange the entries so that matrix products have the intended meaning.

Check your reasoning

F(x,y)=(2x+y,x2)F(x,y)=(2x+y,x^2). Give JFJ_F as ordered rows.

  1. A(2,2x);(1,0)(2,2x);(1,0)
  2. B(2,1);(2x,0)(2,1);(2x,0)
  3. C(2,1);(2,0)(2,1);(2,0)
Show answer and explanation
(2,1);(2x,0)(2,1);(2x,0)

Output 2 gives (2x,0)(2x,0).

03Keep the output and input counts separate#

Now let H(x,y)=(x+y, x2, 2y)H(x,y)=(x+y,\ x^2,\ 2y). There are three outputs and two inputs, so we need three rows and two columns:

JH(x,y)=(112x002).J_H(x,y)=\begin{pmatrix}1&1\\2x&0\\0&2\end{pmatrix}.

The second row's zero records that x2x^2 does not depend on yy. The third row's zero records that 2y2y does not depend on xx.

Zero entries are part of the map. Removing them would lose the alignment between derivatives and input coordinates.

A Jacobian need not be square. A model can turn two features into three outputs, or many parameters into one loss. Count outputs and inputs before calculating entries.

Check your reasoning

F(x,y)=(x,y,2x)F(x,y)=(x,y,2x). Repair an omitted output 3. Give the ordered rows of JFJ_F.

  1. A(1,0);(0,1)(1,0);(0,1)
  2. B(1,0,2);(0,1,0)(1,0,2);(0,1,0)
  3. C(1,0);(0,1);(2,0)(1,0);(0,1);(2,0)
Show answer and explanation
(1,0);(0,1);(2,0)(1,0);(0,1);(2,0)

Keep all three output rows.

04Evaluate the derivative at a point#

Return to F(x,y)=(x2+y,xy)F(x,y)=(x^2+y,xy) and choose p=(1,3)p=(1,3). Evaluating the function gives F(p)=(4,3)F(p)=(4,3). Evaluating the Jacobian gives

JF(p)=(2131).J_F(p)=\begin{pmatrix}2&1\\3&1\end{pmatrix}.

The output is a pair of values; the Jacobian is a table of rates. In particular, the 33 in the bottom-left position means the second output's local rate with respect to xx is three at this point.

When this function follows another function, its input may be an intermediate output rather than the original starting point. The notation in parentheses tells you where to evaluate.

For example, JF(G(p))J_F(G(p)) says: calculate G(p)G(p), then put those coordinates into the derivative formulas for FF. It does not mean multiply JFJ_F by GG or by pp.

Check your reasoning

F(a,b)=(ab,a+b2)F(a,b)=(ab,a+b^2). At (a,b)=(2,1)(a,b)=(2,1), give the ordered rows of JFJ_F.

  1. A(1,2);(1,2)(1,2);(1,2)
  2. B(2,1);(2,1)(2,1);(2,1)
  3. C(2,0);(0,2)(2,0);(0,2)
Show answer and explanation
(1,2);(1,2)(1,2);(1,2)

Differentiate in a, then b.

05Use the Jacobian as a local linear map#

For a small input change Δp\Delta p, a differentiable vector map satisfies the first-order approximation

F(p+Δp)≈F(p)+JF(p)Δp.\begin{gathered}F(p+\Delta p)\\\approx F(p)+J_F(p)\Delta p.\end{gathered}

The Jacobian maps an input change to an approximate output change. It does not replace the original nonlinear function for arbitrary inputs.

At p=(1,3)p=(1,3), choose Δp=(0.01,−0.02)T\Delta p=(0.01,-0.02)^T. Our Jacobian predicts

JF(p)Δp=(2(0.01)−0.023(0.01)−0.02)=(00.01).\begin{gathered}J_F(p)\Delta p\\=\begin{pmatrix}2(0.01)-0.02\\3(0.01)-0.02\end{pmatrix}\\=\begin{pmatrix}0\\0.01\end{pmatrix}.\end{gathered}

The two contributions to the first output cancel to first order, while the second output is predicted to increase by 0.010.01.

The actual output at (1.01,2.98)(1.01,2.98) is (4.0001,3.0098)(4.0001,3.0098). Compared with F(p)=(4,3)F(p)=(4,3), the actual change is (0.0001,0.0098)(0.0001,0.0098), close to the prediction.

The remaining terms are nonlinear effects. This local-map interpretation explains why the chain rule multiplies Jacobians: a small change passes through one local map, then the next.

Key takeaway

Outputs choose rows; inputs choose columns.

  • Construct the Jacobian of a vector-valued map.

Further questions

Is a scalar gradient the same shape?
We write a gradient as an ordered vector. With the output-row convention here, a scalar function’s Jacobian has one row containing those same partials.

Sources & further reading

  1. [1]

Reference this concept

Link to this page, a section, or an individual figure.

Glacius. “Jacobians.” Math behind ML. /learn/c-jacobian