# Describe#

This example focuses on the usage of the `pylops.utils.describe.describe` method, which allows expressing any PyLops operator into its equivalent mathematical representation. This is done with the aid of sympy, a Python library for symbolic computing

```import matplotlib.pyplot as plt
import numpy as np

import pylops
from pylops.utils.describe import describe

plt.close("all")
```

Let’s start by defining 3 PyLops operators. Note that once an operator is defined we can attach a name to the operator; by doing so, this name will be used in the mathematical description of the operator. Alternatively, the describe method will randomly choose a name for us.

```A = pylops.MatrixMult(np.ones((10, 5)))
A.name = "A"
B = pylops.Diagonal(np.ones(5))
B.name = "A"
C = pylops.MatrixMult(np.ones((10, 5)))

# Simple operator
describe(A)

# Transpose
AT = A.T
describe(AT)

AH = A.H
describe(AH)

# Scaled
A3 = 3 * A
describe(A3)

# Sum
D = A + C
describe(D)
```
```A
where: {'A': 'MatrixMult'}
A.T
where: {'A': 'MatrixMult'}
where: {'A': 'MatrixMult'}
3*A
where: {'A': 'MatrixMult'}
A + M
where: {'A': 'MatrixMult', 'M': 'MatrixMult'}
```

So far so good. Let’s see what happens if we accidentally call two different operators with the same name. You will see that PyLops catches that and changes the name for us (and provides us with a nice warning!)

```D = A * B
describe(D)
```
```A*L
where: {'A': 'MatrixMult', 'L': 'Diagonal'}
```

We can move now to something more complicated using various composition operators

```H = pylops.HStack((A * B, C * B))
describe(H)

H = pylops.Block([[A * B, C], [A, A]])
describe(H)
```
```Matrix([[A*L, M*L]])
where: {'A': 'MatrixMult', 'L': 'Diagonal', 'M': 'MatrixMult'}
B
where: {'B': 'Block'}
```

Finally, note that you can get the best out of the describe method if working inside a Jupyter notebook. There, the mathematical expression will be rendered using a LeTex format! See an example notebook.

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

Gallery generated by Sphinx-Gallery