MCPcopy Create free account
hub / github.com/ActiveState/code / partial

Function partial

recipes/Python/580610_Auto_differentiation/recipe-580610.py:181–192  ·  view source on GitHub ↗

Partial derivative at a given point >>> func = lambda x, y: x*y + sin(x) >>> point = (2.5, 3.5) >>> partial(func, point, 0) # Partial with respect to x 2.6988563844530664 >>> partial(func, point, 1) # Partial with respect to y

(func, point, index)

Source from the content-addressed store, hash-verified

179## Vector Functions ######################################################
180
181def partial(func, point, index):
182 ''' Partial derivative at a given point
183
184 >>> func = lambda x, y: x*y + sin(x)
185 >>> point = (2.5, 3.5)
186 >>> partial(func, point, 0) # Partial with respect to x
187 2.6988563844530664
188 >>> partial(func, point, 1) # Partial with respect to y
189 2.5
190
191 '''
192 return d(func(*[Num(x, i==index) for i, x in enumerate(point)]))
193
194def gradient(func, point):
195 ''' Vector of the partial derivatives of a scalar field

Callers 15

recipe-511473.pyFile · 0.85
recipe-578000.pyFile · 0.85
gradientFunction · 0.85
_async_helperMethod · 0.85
__prepare__Method · 0.85
find_in_moduleFunction · 0.85
state_machineFunction · 0.85
pickerFunction · 0.85
recipe-577922.pyFile · 0.85
kfpartialFunction · 0.85
__get__Method · 0.85
setMethod · 0.85

Calls 4

NumClass · 0.70
dFunction · 0.50
funcFunction · 0.50
enumerateFunction · 0.50

Tested by

no test coverage detected