pylops.Gradient#

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

Gradient.

Apply gradient operator to a multi-dimensional array.

Note

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

Parameters
dimstuple

Number of samples for each dimension.

samplingtuple, optional

Sampling steps for each direction.

edgebool, optional

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

kindstr, optional

Derivative kind (forward, centered, or backward).

dtypestr, optional

Type of elements in input array.

Notes

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.

Methods

__init__(dims[, sampling, edge, kind, ...])

adjoint()

apply_columns(cols)

Apply subset of columns of operator

cond([uselobpcg])

Condition number of linear operator.

conj()

Complex conjugate operator

div(y[, niter, densesolver])

Solve the linear problem \(\mathbf{y}=\mathbf{A}\mathbf{x}\).

dot(x)

Matrix-matrix or matrix-vector multiplication.

eigs([neigs, symmetric, niter, uselobpcg])

Most significant eigenvalues of linear operator.

matmat(X)

Matrix-matrix multiplication.

matvec(x)

Matrix-vector multiplication.

reset_count()

Reset counters

rmatmat(X)

Matrix-matrix multiplication.

rmatvec(x)

Adjoint matrix-vector multiplication.

todense([backend])

Return dense matrix.

toimag([forw, adj])

Imag operator

toreal([forw, adj])

Real operator

tosparse()

Return sparse matrix.

trace([neval, method, backend])

Trace of linear operator.

transpose()

Examples using pylops.Gradient#

Derivatives

Derivatives