python - 将图像 channel 顺序从 channel 第一个更改为最后一个

标签 python numpy

我想将此 numpy 图像数组的顺序更改为 channel_last training_data : (2387, 1, 350, 350) 到 (2387,350,350,1) 验证数据 : (298, 1, 350, 350) 到 (298, 350, 350, 1) testing_data : (301, 1, 350, 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

最佳答案

你需要像这样的 np.transpose 方法:

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

其他的也一样

关于python - 将图像 channel 顺序从 channel 第一个更改为最后一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49558818/

相关文章:

python - 在 jitted 函数中两次反转 numpy 数组的 View 使函数运行得更快

python - Numba 中的 bool 签名

python - 在 Python 2 或 3 中,如何同时获取系统调用的返回码和返回字符串?

python - 如何在 Python 中对列表进行切片

python - 优化 python、numpy 中的矩阵运算

python - 在 Numpy 1.6.1 中将 float32 数组转换为 datetime64

python - BeautifulSoup : SyntaxError: invalid character in identifier

Python 非整数 float

python - 权限错误 : [Errno 13] Permission denied: 'C:\\Program Files\\Python35\\Lib\\site-packages\\six.py'

Python:将方阵提高到负半幂