from keras.preprocessing import image
import numpy as np
img = test_features[0, :, :, 0:1]
print(img.shape)
# (150,150,1)
我不知道如何将该图像转换为(150,150,3)
答案 0 :(得分:1)
您可以使用tile
:
In [1]: import numpy as np
In [2]: img = np.ones((150, 150, 1))
In [3]: new = np.tile(img, 3)
In [4]: new.shape
Out[4]: (150, 150, 3)
例如,如果img
是:
array([[[1],
[2],
[3]],
[[4],
[5],
[6]],
[[7],
[8],
[9]]])
np.tile(img, 3)
将是:
array([[[1, 1, 1],
[2, 2, 2],
[3, 3, 3]],
[[4, 4, 4],
[5, 5, 5],
[6, 6, 6]],
[[7, 7, 7],
[8, 8, 8],
[9, 9, 9]]])