Partial derivatives and gradients
Quick answer
A partial derivative changes one input while holding the others fixed. The gradient collects all partial derivatives of a scalar-valued function into a vector, in a declared parameter order. If the function is differentiable, the gradient describes its first-order change in every direction. For a Euclidean unit direction, the gradient points toward the steepest local increase when it is nonzero.
Differentiate one coordinate at a time
Use L(a,b)=(a−2)²+2(b+1)². Holding b fixed gives ∂L/∂a=2(a−2); holding a fixed gives ∂L/∂b=4(b+1). We use column-vector notation mathematically and a two-element list in code.
def gradient(a,b): return [2*(a-2),4*(b+1)]print(gradient(4,0))print(gradient(2,-1))Expected output:
[4, 4][0, 0]At (4,0), both coordinates have positive local slopes. The second output is the zero gradient at the minimum of this particular loss.
Directional derivatives
For differentiable L and a unit direction u, DᵤL = ∇L · u. At (4,0), the gradient is [4,4]. Along [1,0] the directional derivative is 4; along [−1,0] it is −4. Along a unit vector perpendicular to the gradient it is zero. Normalize a nonzero direction first if the question asks for rate per unit distance.
import mathg = [4,4]for u in [[1,0],[-1,0],[1,-1]]: length = math.sqrt(sum(x*x for x in u)) print(round(sum(a*b for a,b in zip(g,u))/length,6))Expected output:
4.0-4.00.0The perpendicular direction has zero first-order change, but the loss can still increase at second order.
Common mistakes
A gradient is not a parameter update until an optimizer chooses a step. Partial derivatives may exist without full differentiability: the first-order linear approximation must hold in all directions. A zero gradient does not tell us the loss value or prove generalization.
Practice and next steps
Find the gradient at (0,1) and its directional derivative along [0,1]. Compare the signs of both partial derivatives. Next, combine derivatives through a chain of operations.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Partial derivatives and gradients — knowledge check
Apply calculus and differentiation to small original examples.
What remains fixed when differentiating with respect to a?
For L=a²+3b², what is ∇L at (1,2)?
For gradient [3,4], what is the directional derivative along [0,1]?
What is required for the direction to represent rate per unit distance?
Does a zero first-order directional derivative guarantee no change over a finite step?