PyLops PyLops PyLops
/

Getting started:

  • 🖥️ Installation
  • 🎮 GPU / TPU Support
  • 🔗 Extensions
  • 📚 Tutorials
    • 01. The LinearOperator
    • 02. The Dot-Test
    • 03. Solvers
    • 03. Solvers (Advanced)
    • 04. Bayesian Inversion
    • 05. Image deblurring
    • 06. 2D Interpolation
    • 07. Post-stack inversion
    • 08. Pre-stack (AVO) inversion
    • 09. Multi-Dimensional Deconvolution
    • 10. Marchenko redatuming by inversion
    • 11. Radon filtering
    • 12. Seismic regularization
    • 13. Deghosting
    • 14. Seismic wavefield decomposition
    • 15. Least-squares migration
    • 16. CT Scan Imaging
    • 17. Real/Complex Inversion
    • 18. Deblending
    • 19. Image Domain Least-squares migration
    • 20. Torch Operator
    • 21. JAX Operator
    • 22. Time-shift estimation
  • 🖼 Gallery
    • 1D Smoothing
    • 1D, 2D and 3D Sliding
    • 2D Smoothing
    • 3D Smoothing
    • AVO modelling
    • Acoustic Wave Equation modelling
    • Bayesian Linear Regression
    • Bilinear Interpolation
    • Blending
    • CGLS and LSQR Solvers
    • Causal Integration
    • Chirp Radon Transform
    • Conj
    • Convolution
    • Derivatives
    • Describe
    • Diagonal
    • Discrete Cosine Transform
    • Flip along an axis
    • Fourier Radon Transform
    • Fourier Transform
    • Identity
    • Imag
    • L1-L1 IRLS
    • Linear Regression
    • MP, OMP, ISTA and FISTA
    • MRI modelling
    • Matrix Multiplication
    • Multi-Dimensional Convolution
    • Non-stationary Convolution
    • Non-stationary Filter Estimation
    • Normal Moveout (NMO) Correction
    • Operators concatenation
    • Operators with Multithreading/Multiprocessing
    • PWD-based slope estimation and structural smoothing
    • Padding
    • Patching
    • PhaseShift operator
    • Polynomial Regression
    • Pre-stack modelling
    • Radon Transform
    • Real
    • Restriction and Interpolation
    • Roll
    • Seislet transform
    • Shift
    • Slope estimation via Structure Tensor algorithm
    • Spread How-to
    • Sum
    • Symmetrize
    • Synthetic seismic
    • Tapers
    • Total Variation (TV) Regularization
    • Transpose
    • Wavelet estimation
    • Wavelet transform
    • Wavelets
    • Zero
  • ❓ Frequenty Asked Questions

Reference documentation:

  • 🔧 PyLops API
    • pylops.LinearOperator
    • pylops.FunctionOperator
    • pylops.MemoizeOperator
    • pylops.PyTensorOperator
    • pylops.TorchOperator
    • pylops.JaxOperator
    • pylops.MatrixMult
    • pylops.Identity
    • pylops.Zero
    • pylops.Diagonal
    • pylops.Transpose
    • pylops.Flip
    • pylops.Roll
    • pylops.Pad
    • pylops.Sum
    • pylops.Symmetrize
    • pylops.Restriction
    • pylops.Regression
    • pylops.LinearRegression
    • pylops.CausalIntegration
    • pylops.Spread
    • pylops.VStack
    • pylops.HStack
    • pylops.Block
    • pylops.BlockDiag
    • pylops.Kronecker
    • pylops.Real
    • pylops.Imag
    • pylops.Conj
    • pylops.ToCupy
    • pylops.Smoothing1D
    • pylops.Smoothing2D
    • pylops.SmoothingND
    • pylops.FirstDerivative
    • pylops.SecondDerivative
    • pylops.Laplacian
    • pylops.Gradient
    • pylops.FirstDirectionalDerivative
    • pylops.SecondDirectionalDerivative
    • pylops.signalprocessing.Convolve1D
    • pylops.signalprocessing.Convolve2D
    • pylops.signalprocessing.ConvolveND
    • pylops.signalprocessing.NonStationaryConvolve1D
    • pylops.signalprocessing.NonStationaryConvolve2D
    • pylops.signalprocessing.NonStationaryConvolve3D
    • pylops.signalprocessing.NonStationaryFilters1D
    • pylops.signalprocessing.NonStationaryFilters2D
    • pylops.signalprocessing.Interp
    • pylops.signalprocessing.InterpCubicSpline
    • pylops.signalprocessing.Bilinear
    • pylops.signalprocessing.FFT
    • pylops.signalprocessing.FFT2D
    • pylops.signalprocessing.FFTND
    • pylops.signalprocessing.Shift
    • pylops.signalprocessing.DWT
    • pylops.signalprocessing.DWT2D
    • pylops.signalprocessing.DWTND
    • pylops.signalprocessing.DCT
    • pylops.signalprocessing.DTCWT
    • pylops.signalprocessing.Seislet
    • pylops.signalprocessing.Radon2D
    • pylops.signalprocessing.Radon3D
    • pylops.signalprocessing.FourierRadon2D
    • pylops.signalprocessing.FourierRadon3D
    • pylops.signalprocessing.ChirpRadon2D
    • pylops.signalprocessing.ChirpRadon3D
    • pylops.signalprocessing.PWSprayer2D
    • pylops.signalprocessing.PWSmoother2D
    • pylops.signalprocessing.Sliding1D
    • pylops.signalprocessing.Sliding2D
    • pylops.signalprocessing.Sliding3D
    • pylops.signalprocessing.Patch2D
    • pylops.signalprocessing.Patch3D
    • pylops.signalprocessing.Fredholm1
    • pylops.waveeqprocessing.PressureToVelocity
    • pylops.waveeqprocessing.UpDownComposition2D
    • pylops.waveeqprocessing.UpDownComposition3D
    • pylops.waveeqprocessing.BlendingContinuous
    • pylops.waveeqprocessing.BlendingGroup
    • pylops.waveeqprocessing.BlendingHalf
    • pylops.waveeqprocessing.MDC
    • pylops.waveeqprocessing.PhaseShift
    • pylops.waveeqprocessing.Kirchhoff
    • pylops.waveeqprocessing.AcousticWave2D
    • pylops.avo.avo.AVOLinearModelling
    • pylops.avo.poststack.PoststackLinearModelling
    • pylops.avo.prestack.PrestackLinearModelling
    • pylops.avo.prestack.PrestackWaveletModelling
    • pylops.medical.CT2D
    • pylops.medical.MRI2D
    • pylops.optimization.basesolver.Solver
    • pylops.optimization.cls_basic.CG
    • pylops.optimization.cls_basic.CGLS
    • pylops.optimization.cls_basic.LSQR
    • pylops.optimization.basic.cg
    • pylops.optimization.basic.cgls
    • pylops.optimization.basic.lsqr
    • pylops.optimization.cls_leastsquares.NormalEquationsInversion
    • pylops.optimization.cls_leastsquares.RegularizedInversion
    • pylops.optimization.cls_leastsquares.PreconditionedInversion
    • pylops.optimization.leastsquares.normal_equations_inversion
    • pylops.optimization.leastsquares.regularized_inversion
    • pylops.optimization.leastsquares.preconditioned_inversion
    • pylops.optimization.cls_sparsity.IRLS
    • pylops.optimization.cls_sparsity.OMP
    • pylops.optimization.cls_sparsity.ISTA
    • pylops.optimization.cls_sparsity.FISTA
    • pylops.optimization.cls_sparsity.SPGL1
    • pylops.optimization.cls_sparsity.SplitBregman
    • pylops.optimization.sparsity.irls
    • pylops.optimization.sparsity.omp
    • pylops.optimization.sparsity.ista
    • pylops.optimization.sparsity.fista
    • pylops.optimization.sparsity.spgl1
    • pylops.optimization.sparsity.splitbregman
    • pylops.optimization.callback.Callbacks
    • pylops.optimization.callback.CostNanInfCallback
    • pylops.optimization.callback.CostToDataCallback
    • pylops.optimization.callback.CostToInitialCallback
    • pylops.optimization.callback.MetricsCallback
    • pylops.waveeqprocessing.SeismicInterpolation
    • pylops.waveeqprocessing.Deghosting
    • pylops.waveeqprocessing.WavefieldDecomposition
    • pylops.waveeqprocessing.MDD
    • pylops.waveeqprocessing.Marchenko
    • pylops.waveeqprocessing.LSM
    • pylops.avo.poststack.PoststackInversion
    • pylops.avo.prestack.PrestackInversion
  • 🔩 PyLops Utilities
    • pylops.utils.dottest
    • pylops.utils.decorators.add_ndarray_support_to_solver
    • pylops.utils.decorators.disable_ndarray_multiplication
    • pylops.utils.decorators.reshaped
    • pylops.utils.describe.describe
    • pylops.utils.estimators.trace_hutchinson
    • pylops.utils.estimators.trace_hutchpp
    • pylops.utils.estimators.trace_nahutchpp
    • pylops.utils.metrics.mae
    • pylops.utils.metrics.mse
    • pylops.utils.metrics.snr
    • pylops.utils.metrics.psnr
    • pylops.avo.avo.zoeppritz_scattering
    • pylops.avo.avo.zoeppritz_element
    • pylops.avo.avo.zoeppritz_pp
    • pylops.avo.avo.approx_zoeppritz_pp
    • pylops.avo.avo.akirichards
    • pylops.avo.avo.fatti
    • pylops.avo.avo.ps
    • pylops.utils.scalability_test
    • pylops.signalprocessing.sliding1d.sliding1d_design
    • pylops.signalprocessing.sliding2d.sliding2d_design
    • pylops.signalprocessing.sliding3d.sliding3d_design
    • pylops.signalprocessing.patch2d.patch2d_design
    • pylops.signalprocessing.patch3d.patch3d_design
    • pylops.utils.seismicevents.makeaxis
    • pylops.utils.seismicevents.linear2d
    • pylops.utils.seismicevents.parabolic2d
    • pylops.utils.seismicevents.hyperbolic2d
    • pylops.utils.seismicevents.linear3d
    • pylops.utils.seismicevents.parabolic3d
    • pylops.utils.seismicevents.hyperbolic3d
    • pylops.waveeqprocessing.marchenko.directwave
    • pylops.utils.signalprocessing.convmtx
    • pylops.utils.signalprocessing.nonstationary_convmtx
    • pylops.utils.signalprocessing.dip_estimate
    • pylops.utils.signalprocessing.slope_estimate
    • pylops.utils.signalprocessing.pwd_slope_estimate
    • pylops.utils.tapers.taper2d
    • pylops.utils.tapers.taper3d
    • pylops.utils.tapers.tapernd
    • pylops.utils.wavelets.gaussian
    • pylops.utils.wavelets.klauder
    • pylops.utils.wavelets.ormsby
    • pylops.utils.wavelets.ricker

Getting involved:

  • 🖌️ Implementing new operators
  • 🔥 Implementing new solvers
  • ❤️ Contributing
  • 🗞 Changelog
  • 🔖 Papers using PyLops
  • ✏️ How to cite
  • 🧑‍🤝‍🧑 Contributors
  1. PyLops /
  2. 🖼 Gallery /
  3. Identity

Note

Go to the end to download the full example code.

Identity¶

This example shows how to use the pylops.Identity operator to transfer model into data and viceversa.

import matplotlib.gridspec as pltgs
import matplotlib.pyplot as plt
import numpy as np

import pylops

plt.close("all")

Let’s define an identity operator \(\mathbf{Iop}\) with same number of elements for data and model (\(N=M\)).

N, M = 5, 5
x = np.arange(M)
Iop = pylops.Identity(M, dtype="int")

y = Iop * x
xadj = Iop.H * y

gs = pltgs.GridSpec(1, 6)
fig = plt.figure(figsize=(7, 4))
ax = plt.subplot(gs[0, 0:3])
im = ax.imshow(np.eye(N), cmap="rainbow")
ax.set_title("A", size=20, fontweight="bold")
ax.set_xticks(np.arange(N - 1) + 0.5)
ax.set_yticks(np.arange(M - 1) + 0.5)
ax.grid(linewidth=3, color="white")
ax.xaxis.set_ticklabels([])
ax.yaxis.set_ticklabels([])
ax = plt.subplot(gs[0, 3])
ax.imshow(x[:, np.newaxis], cmap="rainbow")
ax.set_title("x", size=20, fontweight="bold")
ax.set_xticks([])
ax.set_yticks(np.arange(M - 1) + 0.5)
ax.grid(linewidth=3, color="white")
ax.xaxis.set_ticklabels([])
ax.yaxis.set_ticklabels([])
ax = plt.subplot(gs[0, 4])
ax.text(
    0.35,
    0.5,
    "=",
    horizontalalignment="center",
    verticalalignment="center",
    size=40,
    fontweight="bold",
)
ax.axis("off")
ax = plt.subplot(gs[0, 5])
ax.imshow(y[:, np.newaxis], cmap="rainbow")
ax.set_title("y", size=20, fontweight="bold")
ax.set_xticks([])
ax.set_yticks(np.arange(N - 1) + 0.5)
ax.grid(linewidth=3, color="white")
ax.xaxis.set_ticklabels([])
ax.yaxis.set_ticklabels([])
fig.colorbar(im, ax=ax, ticks=[0, 1], pad=0.3, shrink=0.7)
plt.tight_layout()
A, x, y

Similarly we can consider the case with data bigger than model

N, M = 10, 5
x = np.arange(M)
Iop = pylops.Identity(N, M, dtype="int")

y = Iop * x
xadj = Iop.H * y

print(f"x = {x} ")
print(f"I*x = {y} ")
print(f"I'*y = {xadj} ")
x = [0 1 2 3 4]
I*x = [0 1 2 3 4 0 0 0 0 0]
I'*y = [0 1 2 3 4]

and model bigger than data

N, M = 5, 10
x = np.arange(M)
Iop = pylops.Identity(N, M, dtype="int")

y = Iop * x
xadj = Iop.H * y

print(f"x = {x} ")
print(f"I*x = {y} ")
print(f"I'*y = {xadj} ")
x = [0 1 2 3 4 5 6 7 8 9]
I*x = [0 1 2 3 4]
I'*y = [0 1 2 3 4 0 0 0 0 0]

Note that this operator can be useful in many real-life applications when for example we want to manipulate a subset of the model array and keep intact the rest of the array. For example:

\[\begin{split}\begin{bmatrix} \mathbf{A} \quad \mathbf{I} \end{bmatrix} \begin{bmatrix} \mathbf{x_1} \\ \mathbf{x_2} \end{bmatrix} = \mathbf{A} \mathbf{x_1} + \mathbf{x_2}\end{split}\]

Refer to the tutorial on Optimization for more details on this.

Total running time of the script: (0 minutes 0.130 seconds)

Download Jupyter notebook: plot_identity.ipynb

Download Python source code: plot_identity.py

Download zipped: plot_identity.zip

Gallery generated by Sphinx-Gallery

Previous
Fourier Transform
Next
Imag

2026, PyLops Development Team

Made with Sphinx and Shibuya theme.