[英]How to transpose 3D matrix like 2D?
I want to transpose 3D matrix but without touching most inner list. 我想转置3D矩阵,但不涉及大多数内部列表。 The 3D matrix is numpy array of an image and the goal of transposition is to rotate image but not to change pixel values(rgb).
3D矩阵是图像的numpy数组,转置的目的是旋转图像而不改变像素值(rgb)。
image = np.array(
[
[[15, 15, 25], [50, 50, 50], [90, 90, 90], [255, 255, 255], [127, 127, 127]],
[[121, 121, 121], [75, 10, 75], [187, 187, 187], [0, 0, 0], [210, 50, 100]],
[[31, 31, 31], [63, 63, 63], [87, 87, 87], [63, 63, 63], [63, 63, 63]],
[[95, 95, 95], [95, 95, 95], [115, 115, 115], [87, 87, 87], [95, 95, 95]],
[[95, 95, 95], [63, 63, 63], [63, 63, 63], [87, 87, 87], [100, 250, 250]]
], dtype=np.uint8)
The result should be something like this. 结果应该是这样的。
result = np.array(
[
[[15, 15, 25], [121, 121, 121], [31, 31, 31], [95, 95, 95], [95, 95, 95]],
[[50, 50, 50], [75, 10, 75], [63, 63, 63], [95, 95, 95], [63, 63, 63]],
[[90, 90, 90], [187, 187, 187], [87, 87, 87], [115, 115, 115], [63, 63, 63]],
[[255, 255, 255], [0, 0, 0], [63, 63, 63], [87, 87, 87], [87, 87, 87]],
[[127, 127, 127], [210, 50, 100], [63, 63, 63], [95, 95, 95], [100, 250, 250]]
], dtype=np.uint8)
np.swapaxes(image, 0, 1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.