Python NumPy - angled slice of 3D array
You can try with np.diagonal
:
arr = np.array([[[0 ,1 ,2],
[3 ,4 ,5],
[6 ,7 ,8]],
[[9 ,10 ,11],
[12 ,13 ,14],
[15 ,16 ,17]],
[[18 ,19 ,20],
[21 ,22 ,23],
[24 ,25 ,26]]])
np.diagonal(arr).T
array([[ 0, 1, 2],
[12, 13, 14],
[24, 25, 26]])
In [145]: arr[np.arange(3), np.arange(3),:]
Out[145]:
array([[ 0, 1, 2],
[12, 13, 14],
[24, 25, 26]])