Logo
v1.18.3

Getting started:

  • Installation
  • Advanced installation
  • GPU support
  • Extensions
  • Tutorials
  • Gallery
    • 1D Smoothing
    • 1D, 2D and 3D Sliding
    • 2D Patching
    • 2D Smoothing
    • AVO modelling
    • Bilinear Interpolation
    • CGLS and LSQR Solvers
    • Causal Integration
    • Chirp Radon Transform
    • Conj
    • Convolution
    • Derivatives
    • Describe
    • Diagonal
    • Flip along an axis
    • Fourier Transform
    • Identity
    • Imag
    • Linear Regression
    • MP, OMP, ISTA and FISTA
    • Matrix Multiplication
    • Multi-Dimensional Convolution
    • Normal Moveout (NMO) Correction
    • Operators concatenation
    • Operators with Multiprocessing
    • Padding
    • 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
    • Zero
  • FAQs

Reference documentation:

  • PyLops API
  • PyLops Utilities

Getting involved:

  • Implementing new operators
  • Contributing
  • Changelog
  • Roadmap
  • Papers using PyLops
  • Citing
  • Credits

Repository

  • Source Code
  • Contributing
PyLops
  • Docs »
  • Gallery »
  • Identity
  • Improve this page

Note

Click here 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, 3))
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)
A, x, y

Out:

<matplotlib.colorbar.Colorbar object at 0x7f90d0a10b38>

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("x = %s " % x)
print("I*x = %s " % y)
print("I'*y = %s " % xadj)

Out:

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("x = %s " % x)
print("I*x = %s " % y)
print("I'*y = %s " % xadj)

Out:

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.165 seconds)

Download Python source code: plot_identity.py
Download Jupyter notebook: plot_identity.ipynb

Gallery generated by Sphinx-Gallery

Next Previous

© Copyright 2022, PyLops Development Team Revision 31048ec1.

Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: v1.18.3
Versions
latest
stable
v1.18.3
v1.18.2
v1.18.0
v1.17.0
v1.16.0
v1.15.0
v1.14.0
v1.13.0
v1.12.0
v1.11.1
v1.11.0
v1.10.0
v1.9.1
v1.9.0
v1.8.0
v1.7.0
v1.6.0
v1.5.0
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.