两种方法都可以:expand_dims,concatenate
import numpy as np a=np.asarray([[10,20],[101,201]]) # a=a[:,:,np.newaxis] # print(a.shape) # b= a.repeat([3],axis=2) # print(b.shape,b) image = np.expand_dims(a, axis=2) image = np.concatenate((image, image, image), axis=-1) print(image)
axis=-1就是最后一个通道