简体   繁体   中英

Rotating 5D cube with NumPy

I got 2x 5D cubes in the shape of [1, 4, 21, 302, 302] that I need to compare with each other. However the first is rotated with respect to the second. If I work with just these two images I can fix it by applying np.rot90(np.flipud(a)) to the left image, with a being that 302x302 image. How do I apply this to the entire cube without changing the other axes?

在此输入图像描述

Rotating the image like you're describing it is simply transposing/swapping the two axes x and y. For a single image in a 2D array, you would simply do

img.T

And for a 5D tensor like yours where the image is contained in the last two axes, you would do

img.transpose(0, 1, 2, 4, 3)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM