将图像通道顺序从“通道优先”更改为“las”

2024-09-27 02:17:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我想把这个numpy images数组的顺序改为channel_last 培训数据:(2387,1350,350)至(2387350350,1) 验证数据:(298,1350,350)到(298350,350,1) 测试数据:(301,1350,350)到(301,350,350,1)

我试过了,但没用

np.rollaxis(training_data,0,3).shape
np.rollaxis(validation_data,0,3).shape
np.rollaxis(testing_data,0,3).shape

Tags: 数据numpydata顺序nptrainingchannel数组
2条回答

您需要这样的np.transpose方法:

training_data = np.transpose(training_data, (0, 2,3,1)

其他的也一样

如果要移动的轴的长度为1,则简单的重塑即可:

a = np.arange(24).reshape(2, 1, 3, 4)

# Three different methods:
b1 = a.reshape(2, 3, 4, 1)
b2 = np.moveaxis(a, 1, 3)
b3 = a.transpose(0, 2, 3, 1)

# All give the same result:
np.all(b1 == b2) and np.all(b2 == b3)
# True

相关问题 更多 >

    热门问题