Samuel Bancroft - 1 year ago 81

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.

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

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.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**