我有一组来自 Tiff 文件的 4 维数据。
image_stack = io.imread(path, plugin='tifffile')
print(image_stack.shape)
>>> (21, 10, 1331, 1126)
所以最后 2 个维度是图像分辨率。 10 是因为我在给定时间有 10 个相同图像的切片(在 z 轴上) 21 是因为所有这些图像每秒都会拍摄一次。
如何交换 21 和 10 尺寸?
最佳答案
您可以将前两个轴与 swapaxes
交换:
a = np.random.rand(21, 10, 1331, 1126)
a.swapaxes(1,0).shape
# (10, 21, 1331, 1126)
或者用 rollaxis
向后移动第二个轴:
np.rollaxis(a, 1).shape
# (10, 21, 1331, 1126)
关于python - 如何交换数组中的二维,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61900669/