我在移动3轴到1号位置时遇到了麻烦。我想将3轴移动到第一个69位置。这是一个机器学习数据集,PyTorch 只接受 3x69x69 格式的数据。谢谢你的帮助
# To get the images and labels from file
with h5py.File(r"C:\Users\ajbur\Downloads\Galaxy10.h5", 'r') as F:
images = np.array(F['images'])
labels = np.array(F['ans'])
np.shape(images)
np.moveaxis(images,0,-1).shape
np.shape(images)
输出是 [20000, 69, 69, 3],我希望它是 [20000, 3, 69, 69] 。
的第二个和第三个参数。moveaxis
是源和目的。要将最后一个轴移动到第二个位置,你可以这样做。
a = np.empty([20000, 69, 69, 3])
np.moveaxis(a, -1, 1).shape
>>> (20000, 3, 69, 69)