I want to get the upper "corner" or hypertriangle of a fully symmetric numpy nd array. In other words, i want to slice the array along all its diagonals (with optional offset) and take only the remaining triangle.
# with a 3d array and 0 offset,
a = np.arange(5)
arr=a[:,None,None] + a[None,:,None] + a[None,None,:]
upper_corner(arr,offset=0)
Expected output:
array([[[ 0, 1, 2, 3, 4],
[ 0, 2, 3, 4, 5],
[ 0, 0, 4, 5, 6],
[ 0, 0, 0, 6, 7],
[ 0, 0, 0, 0, 8]],
[[ 0, 2, 3, 4, 5],
[ 0, 0, 4, 5, 6],
[ 0, 0, 0, 6, 7],
[ 0, 0, 0, 0, 8],
[ 0, 0, 0, 0, 0]],
[[ 0, 0, 4, 5, 6],
[ 0, 0, 0, 6, 7],
[ 0, 0, 0, 0, 8],
[ 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0]],
[[ 0, 0, 0, 6, 7],
[ 0, 0, 0, 0, 8],
[ 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0]],
[[ 0, 0, 0, 0, 8],
[ 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0]]])
Is there an indexing or slicing solution for this in n-dimensions?