I am attempting to transform a numpy ndarray in the following manner.
Here is the array I have currently given by rot_F:
# F is laid out to be human readable here
F = np.array(
[
[# Filter 0
[ # Depth 0
[1, -1],
[2, 0]
],
[ # Depth 1
[ 0, 0],
[-1, -1]
]
],
[# Filter 1
[ # Depth 0
[0, -1],
[3, 0]
],
[ # Depth 1
[ 1, 2],
[-1, -1]
]
]
]
)
F = np.moveaxis(F,1,3)
# rotate F by 180 degrees along axes (1,2)
rot_F = np.rot90(F,2,(1,2))
print(rot_F)
OUTPUT FROM print(rot_F):
[[[[ 0 -1]
[ 2 -1]]
[[-1 0]
[ 1 0]]]
[[[ 0 -1]
[ 3 -1]]
[[-1 2]
[ 0 1]]]]
Now I want to turn rot_F into the following:
desired_filters = np.zeros_like(rot_F)
desired_filters[0,:,:,0] = np.array([[0,2],[-1,1]])
desired_filters[0,:,:,1] = np.array([[0,3],[-1,0]])
desired_filters[1,:,:,0] = np.array([[-1,-1],[0,0]])
desired_filters[1,:,:,1] = np.array([[-1,-1],[2,1]])
print(desired_filters)
OUTPUT FROM print(desired_filters):
[[[[ 0 0]
[ 2 3]]
[[-1 -1]
[ 1 0]]]
[[[-1 -1]
[-1 -1]]
[[ 0 2]
[ 0 1]]]]
Basically I am trying stack all of the arrays on 0th depth dimension in rot_F along their own depth dimension and all of the arrays on the 1st depth dimension in rot_F on their own depth dimension while preserving the original shape.
np.rot90. In its code I see the use oftransposeandflip.flipis[::-1]indexing.Fvalues, identifying what has changed inrot_For the desired output is tedious. There's no obvious pattern.