Updated: 2019-01-13

• The gradient is a multi-variable generalization of the derivative
• The gradient is a vector-valued function, as opposed to a derivative, which is scalar-valued.
• Like the derivative, the gradient represents the slope of the tangent of the graph of the function.

• Gradient is (change in x)/(change in y). y, here, is the index, so the difference(distance) between adjacent values is 1.
• The gradient is computed using central differences in the interior and first differences at the boundaries. Read More About Central Differences

• At the boundaries, the first difference is calculated. This means that at each end of the array, the gradient given is simply, the difference between the end two values (divided by 1)
• Away from the boundaries the gradient for a particular index is given by taking the difference between the the values either side and dividing by 2.

## Example

Use Numpy

>>> x = np.array([1, 2, 4, 7, 11, 16], dtype=np.float)
>>> j
array([ 1. ,  1.5,  2.5,  3.5,  4.5,  5. ])

So, the gradient of x is calculated as this:

g[0] = (x[1]-x[0])/1 = (2-1)/1  = 1
g[1] = (x[2]-x[0])/2 = (4-1)/2  = 1.5
g[2] = (x[3]-x[1])/2 = (7-2)/2  = 2.5
g[3] = (x[4]-x[2])/2 = (11-4)/2 = 3.5
g[4] = (x[5]-x[3])/2 = (16-7)/2 = 4.5
g[5] = (x[5]-x[4])/1 = (16-11)/1 = 5

Use Tensorflow

[db,dW,dx] = tf.gradients(C, [b,W,x])
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}