pylops.Gradient(dims, sampling=1, edge=False, dtype='float64', kind='centered')[source]


Apply gradient operator to a multi-dimensional array.


At least 2 dimensions are required, use pylops.FirstDerivative for 1d arrays.

dims : tuple

Number of samples for each dimension.

sampling : tuple, optional

Sampling steps for each direction.

edge : bool, optional

Use reduced order derivative at edges (True) or ignore them (False).

dtype : str, optional

Type of elements in input array.

kind : str, optional

Derivative kind (forward, centered, or backward).

l2op : pylops.LinearOperator

Gradient linear operator


The Gradient operator applies a first-order derivative to each dimension of a multi-dimensional array in forward mode.

For simplicity, given a three dimensional array, the Gradient in forward mode using a centered stencil can be expressed as:

\[\mathbf{g}_{i, j, k} = (f_{i+1, j, k} - f_{i-1, j, k}) / d_1 \mathbf{i_1} + (f_{i, j+1, k} - f_{i, j-1, k}) / d_2 \mathbf{i_2} + (f_{i, j, k+1} - f_{i, j, k-1}) / d_3 \mathbf{i_3}\]

which is discretized as follows:

\[\begin{split}\mathbf{g} = \begin{bmatrix} \mathbf{df_1} \\ \mathbf{df_2} \\ \mathbf{df_3} \end{bmatrix}\end{split}\]

In adjoint mode, the adjoints of the first derivatives along different axes are instead summed together.

Examples using pylops.Gradient