import numpy as np
import matplotlib.pylab as plt
def diff(f,x0,x1,select=1):  # select = -1   is x0 derivation, select =1 is x1 derivation
    h=1e-4
    x0=x0*select*-1
    x1=x1*(select+1)
    y=f((x0+x1)+h)-f((x0+x1)-h)
    return y/(2*h)
def fuction(x):
    return x**2


print(diff(fuction,3,4,-1))

几句代码之实现偏导