Samuel Bancroft - 9 months ago 49

Python Question

If I have a 100x100 2D Numpy array and I want to extract the cross profile that is centred at (50,50) at an angle of 25 degrees (to the horizontal). How can this be achieved?

I have attempted using numpy.diagonal to no avail.

Answer

This is what I would do. Assuming your mat is mymat.

```
import numpy as np
ang = 25
extract = []
for i in range(100):
j = int(50 + (50 - i) * np.tan(ang * np.pi /180))
if j<=99 and j>=0:
extract.append(mymat[i,j])
```

Numbers should be adjusted for other sizes.