def f(x, y):
    return np.sin(x)
x = y = np.arange(-3, 3, 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))])
xy_pairs = np.array([(str(x) + ',' + str(y)) for x, y in zip(np.ravel(X),
    np.ravel(Y))])
Z = zs.reshape(X.shape)
xy_pairs = xy_pairs.reshape(X.shape)
gy, gx = np.gradient(Z, 0.05, 0.05)
Gradient calculation with python