def f(x, y):
    return np.sin(x + y)
x = y = np.arange(-5, 5, 0.05)
X, Y = np.meshgrid(x, y)
zs = np.array([f(x, y) for x, y in zip(np.ravel(X), np.ravel(Y))])
Z = zs.reshape(X.shape)
gx, gy = np.gradient(Z, 0.05, 0.05)
Gradient calculation with python