I want to compute the vertical/horizontal gradient of a matrix/ tensor in PyTorch, just like a numpy function - np.gradient (https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.gradient.html).

Say, the matrix is $G$, $\Delta_w G$ and $\Delta_h G$ are needed. Does any built-in function in PyTorch work like these? Or how can I implement it?

Thanks a lot.