Im trying to get the diagonal (and anti-diagonal) elements of multi-dimensional objects.
The shapes are like (2,2), (3,3,3), (4,4,4,4), (5,5,5,5,5) and so on. I don't think this is too relevant though.
I found ways of getting the diagonal elements, with the .diagonal method of the ndarray, but I can't find anything that would get me the antidiagonal.
So would I have to do this by hand?
[EDIT] So for
array([[[54, 81, 31],
[ 4, 83, 18],
[38, 32, 52]],
[[ 2, 45, 87],
[33, 20, 3],
[85, 31, 35]],
[[ 6, 11, 49],
[39, 76, 75],
[28, 52, 63]]])
So I'd want the "horizontal" diagonals, like:
[54, 45, 49],
[ 4. 20, 75],
etc.
but then these are also horizontal in some sense
[ 6, 45, 31],
[39, 20, 18]
and then "vertical" ones like:
[54, 33, 28],
[81, 20, 52],
etc.
but then these are also vertical:
[6, 33, 38],
[11, 20, 32]
and then this one, however you'd call it
[54, 20, 63]
and then these are also "longer" diagonals, like the previous one (longer in a geometrical sense, if you think of the matrix as a 3d geometrical structure, with the numbers being placed on the vertexes of a cube, and on the middle of the lines between them)
[38, 20, 49],
[6, 20, 52]
Then, a minor diagonal would be one which goes from right to left or bottom to top (but not both at the same time) in this matrix, something like:
[31, 45, 6],
[31, 83, 38] # this is the first classical anti-diagonal in the first matrix
Of course, I did'nt put here all the diagonals, but this is my requirement. I don't need diagonals which are offset from any of the main/anti diagonals.
If you also know this not to be possible, please tell, because I will do it by hand then.